mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
add itertools
(#239)
This commit is contained in:
parent
ab96dbb028
commit
6bf645d738
7
docs/modules/itertools.md
Normal file
7
docs/modules/itertools.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
icon: package
|
||||
label: itertools
|
||||
---
|
||||
|
||||
### `itertools.zip_longest(a, b)`
|
||||
|
File diff suppressed because one or more lines are too long
13
python/itertools.py
Normal file
13
python/itertools.py
Normal file
@ -0,0 +1,13 @@
|
||||
def zip_longest(a, b):
|
||||
a = iter(a)
|
||||
b = iter(b)
|
||||
while True:
|
||||
ai = next(a)
|
||||
bi = next(b)
|
||||
if ai is StopIteration and bi is StopIteration:
|
||||
break
|
||||
if ai is StopIteration:
|
||||
ai = None
|
||||
if bi is StopIteration:
|
||||
bi = None
|
||||
yield ai, bi
|
@ -1606,6 +1606,7 @@ void VM::post_init(){
|
||||
_lazy_modules["typing"] = kPythonLibs_typing;
|
||||
_lazy_modules["datetime"] = kPythonLibs_datetime;
|
||||
_lazy_modules["cmath"] = kPythonLibs_cmath;
|
||||
_lazy_modules["itertools"] = kPythonLibs_itertools;
|
||||
|
||||
try{
|
||||
CodeObject_ code = compile(kPythonLibs_builtins, "<builtins>", EXEC_MODE);
|
||||
|
6
tests/86_itertools.py
Normal file
6
tests/86_itertools.py
Normal file
@ -0,0 +1,6 @@
|
||||
from itertools import zip_longest
|
||||
|
||||
a = [1, 2, 3]
|
||||
b = [2]
|
||||
|
||||
assert list(zip_longest(a, b)) == [(1, 2), (2, None), (3, None)]
|
Loading…
x
Reference in New Issue
Block a user