0
What happens when you "empty" a temporary data structure
What happens when you "empty" a temporary data structure like a generator or the output of the itertools.product function? from itertools import product, permutations letters = ("A", "B") p=product(letters, range(2)) for n in p: print(n) for n in p: print(n) The output of the for loop, instead of a list, is each tuple line-by-line. The output of the final print is an error in in the product function with a memory address. with a list or set, popping out the values gives you [] or set()
3 Antworten
+ 2
itertools.product gives a generator, so once you have exhausted it, it just throws StopIteration, cutting the for loop.
0
@david that code worked finely in my interpreter!!
0
Would you ever get thrown and error?