On this page
itertools.starmap
Prev: itertools.repeat | Up: itertools | Next: itertools.takewhile
Rel: itertools.accumulate, itertools.batched, itertools.chain, itertools.combinations
Ref: docs.python.org — itertools.starmap
Tags: #public #python3 #stdlib #itertools
Import
import itertools
from itertools import starmap
Signature & Overview
itertools.starmap(function, iterable, /)
Return an iterator whose values are returned from the function evaluated with an argument tuple taken from the given sequence.
Usage
from itertools import starmap
pairs = [(2, 5), (3, 2), (10, 3)]
assert list(starmap(pow, pairs)) == [32, 9, 1000]
Gotchas
starmapvs.map: Usemap(fn, xs, ys)when arguments are in separate iterables; usestarmap(fn, pairs)when each item is already a tuple of positional args(x, y).- Positional unpacking only: Each element is unpacked as
fn(*args); it does not unpack dicts as**kwargs.
REPL Inspect
from itertools import starmap
help(starmap)
Linked from
Related notes
- tuts/python3/stdlib_module/itertools/repeat Linked here; links to this page; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/takewhile Linked here; links to this page; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/itertools/accumulate Linked here; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/batched Linked here; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/chain Linked here; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/combinations Linked here; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/combinations_with_replacement shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/compress shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/count shared tags: #itertools, #stdlib