3

The outcome is None with list(a) the second time. Anyone have a clue on that?

>>> test = {1: 2, 3: 4}
>>> a= test.iterkeys()
>>> list(a)
**[1, 3]**
>>> list(a)
**[]**
>>> list(a)
[]
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

7

iterkeys returns an iterator, which, as any iterator, can be iterated over only once.

list consumes the whole iterator, so that the latter can't provide any more values, so the subsequent lists are empty.

ForceBru
  • 43,482
  • 10
  • 63
  • 98