All permutations from 2 lists
Peter Otten
__peter__ at web.de
Wed Mar 2 02:41:20 EST 2022
On 02/03/2022 01:32, Rob Cliffe via Python-list wrote:
> itertools.product returns an iterator (or iterable, I'm not sure of the
> correct technical term).
There's a simple test:
iter(x) is x --> True # iterator
iter(x) is x --> False # iterable
So:
>>> from itertools import product
>>> p = product("ab", [1, 2])
>>> iter(p) is p # iterator
True
>>> items = [1, 2] # iterable
>>> iter(items) is items
False
Another interesting property of (finite) iterators/iterables
list(iterable) == list(iterable) --> Generally True, but not guaranteed.
a = list(iterator) # whatever
b = list(iterator) # [] (*)
(*) Kill the coder if that doesn't hold ;)
More information about the Python-list
mailing list