Merge pull request #25 from apsz3/builtin/enumerate

Add `enumerate` builtin
This commit is contained in:
BLUELOVETH 2023-02-18 09:20:44 +08:00 committed by GitHub
commit 69338f316d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -44,6 +44,12 @@ def any(iterable):
return True
return False
def enumerate(iterable, start=0):
n = start
for elem in iterable:
yield n, elem
n += 1
def sum(iterable):
res = 0
for i in iterable:

View File

@ -199,3 +199,6 @@ assert all([True, 1])
assert not all([False])
assert not all([True, False])
assert not all([False, False])
assert list(enumerate([1,2,3])) == [(0,1), (1,2), (2,3)]
assert list(enumerate([1,2,3], 1)) == [(1,1), (2,2), (3,3)]