Skip to main content
Active reading [<https://en.wiktionary.org/wiki/built-in#Adjective>]. Interpreted "i.e." as meaning "e.g."
Source Link
Peter Mortensen
  • 31.2k
  • 22
  • 110
  • 134

It's possible to access for some builtin iterators via __reduce__, e.g.:

xs = iter([8, 23, 45])

for x in xs:
    print("item #{} = {}".format(xs.__reduce__()[-1], x))

But I'd prefer to use enumerate generally

For other builtinbuilt-in iterators (excluding i.e., for example, Generators and others), that cannot have their index retrieved via reduce, see my answer here if interested: Is it possible to get index of the next item from iterator?Is it possible to get index of the next item from iterator?

It's possible to access for some builtin iterators via __reduce__ e.g.:

xs = iter([8, 23, 45])

for x in xs:
    print("item #{} = {}".format(xs.__reduce__()[-1], x))

But I'd prefer to use enumerate generally

For other builtin iterators (excluding i.e. Generators and others) that cannot have their index retrieved via reduce see my answer here if interested: Is it possible to get index of the next item from iterator?

It's possible to access for some builtin iterators via __reduce__, e.g.:

xs = iter([8, 23, 45])

for x in xs:
    print("item #{} = {}".format(xs.__reduce__()[-1], x))

But I'd prefer to use enumerate generally

For other built-in iterators (excluding, for example, Generators and others), that cannot have their index retrieved via reduce, see my answer here if interested: Is it possible to get index of the next item from iterator?

Source Link

It's possible to access for some builtin iterators via __reduce__ e.g.:

xs = iter([8, 23, 45])

for x in xs:
    print("item #{} = {}".format(xs.__reduce__()[-1], x))

But I'd prefer to use enumerate generally

For other builtin iterators (excluding i.e. Generators and others) that cannot have their index retrieved via reduce see my answer here if interested: Is it possible to get index of the next item from iterator?