mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
Merge branch 'main' of https://github.com/pocketpy/pocketpy
This commit is contained in:
commit
7a145b6c02
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
|
@ -32,6 +32,8 @@ LiteralString = _PLACEHOLDER
|
||||
Iterable = _PLACEHOLDER
|
||||
Generator = _PLACEHOLDER
|
||||
|
||||
Hashable = _PLACEHOLDER
|
||||
|
||||
TypeVar = _PLACEHOLDER
|
||||
Self = _PLACEHOLDER
|
||||
|
||||
|
@ -1622,6 +1622,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);
|
||||
|
@ -729,7 +729,7 @@ void VM::init_builtin_types(){
|
||||
this->Ellipsis = heap._new<Dummy>(_new_type_object("ellipsis"));
|
||||
this->True = heap._new<Dummy>(tp_bool);
|
||||
this->False = heap._new<Dummy>(tp_bool);
|
||||
this->StopIteration = heap._new<Dummy>(_new_type_object("StopIterationType"));
|
||||
this->StopIteration = _all_types[_new_type_object("StopIteration", tp_exception)].obj;
|
||||
|
||||
this->builtins = new_module("builtins");
|
||||
|
||||
|
@ -36,3 +36,21 @@ assert next(i) == 4
|
||||
assert next(i) == 5
|
||||
assert next(i) == StopIteration
|
||||
assert next(i) == StopIteration
|
||||
|
||||
import builtins
|
||||
|
||||
def next(obj):
|
||||
res = builtins.next(obj)
|
||||
if res is StopIteration:
|
||||
raise StopIteration
|
||||
return res
|
||||
|
||||
a = iter([1])
|
||||
assert next(a) == 1
|
||||
|
||||
try:
|
||||
next(a)
|
||||
exit(1)
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
|
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