79557148

Date: 2025-04-05 15:15:49
Score: 3
Natty:
Report 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?

Reasons:
  • Blacklisted phrase (1): Is it possible to
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: Ben Tonks