
April 2, 2020
1:05 p.m.
Ilya Kamenshchikov writes:
I needed reversed(enumerate(x: list)) in my code,
def reversed_enumerated_list(l): return zip(reversed(range(len(l)), reversed(l))
and have discovered that it wound't work.
I wouldn't have expected it to, because enumerate's result is unbounded. But I'm definitely warming to the idea that this should work for iterables with known length. Presumably the same implementation method used for reversed itself would work; not sure if that is what you proposed. The method used to implement reversibility should probably be exposed so that other code that wants a finite enumeration can determine what enumerate has discovered about the underlying iterable.