itertools: Add starmap function

pull/63/merge
pohmelie 2015-12-08 12:16:36 +03:00 zatwierdzone przez Paul Sokolovsky
rodzic 460dd59b16
commit 5477729d50
2 zmienionych plików z 6 dodań i 0 usunięć

Wyświetl plik

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

Wyświetl plik

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