kopia lustrzana https://github.com/micropython/micropython-lib
itertools: Add starmap function
rodzic
460dd59b16
commit
5477729d50
|
@ -51,3 +51,7 @@ def islice(p, start, stop=(), step=1):
|
|||
|
||||
def tee(iterable, n=2):
|
||||
return [iter(iterable)] * n
|
||||
|
||||
def starmap(function, iterable):
|
||||
for args in iterable:
|
||||
yield function(*args)
|
||||
|
|
|
@ -12,3 +12,5 @@ assert list(itertools.islice(g(), 5)) == [123, 123, 123, 123, 123]
|
|||
|
||||
assert list(itertools.islice(itertools.cycle([1, 2, 3]), 10)) == [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
|
||||
assert list(itertools.islice(itertools.cycle(reversed([1, 2, 3])), 7)) == [3, 2, 1, 3, 2, 1, 3]
|
||||
|
||||
assert list(itertools.starmap(lambda x, y: x * y, [[1, 2], [2, 3], [3, 4]])) == [2, 6, 12]
|
||||
|
|
Ładowanie…
Reference in New Issue