-1

When I do:

from itertools import combinations
a = combinations ('pdejffd', 2)
print(list(a))
print(list(a))

the second print outputs [].

Can someone explain me why?

  • 2
    Does this answer your question? [Why can't I iterate twice over the same data?](https://stackoverflow.com/questions/25336726/why-cant-i-iterate-twice-over-the-same-data) You should do `a = list(combinations('pdejffd', 2))` instead – Tomerikoo Oct 27 '20 at 15:21

1 Answers1

1

itertools.combinations returns a generator.

You've already used it up in the first list(a) call.

Alexander
  • 59,041
  • 12
  • 98
  • 151