add itertools (#239)

This commit is contained in:
BLUELOVETH 2024-04-13 23:44:07 +08:00 committed by GitHub
parent ab96dbb028
commit 6bf645d738
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 0 deletions

View 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
View 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

View File

@ -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
View 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)]