
On Thu, Jan 21, 2021 at 10:43 AM Neil Girdhar <mistersheik@gmail.com> wrote:
I've seen this proposed here before. The general idea is that some iterator transformations (like enumerate) should return sequences when they're applied to sequences.
I'm not so sure -- I don't think I want a sequence returned. In fact, in this case, just the opposite. If you wanted a sequence, you could simply do: reversed(list(enumerate(the_iterable))) Rather, you want (or I want, anyway) is for various iterators to be able to do things that require a Sequence, when given a Sequence. Or, maybe not even a full Sequence, but rather, some particular aspect of a sequence -- like the length, or indexability. enumerate() with a reversed flag is one. Another, I'd like is islice to support negative indexing for indexing from the end. There are probably many others. I'd love to see these supported. For this example: enumerate(an_iterable, reversed=True) would "just work" if an_iterable had a __len__ and a __getitem__. It would raise a TypeError if passed a non-lengthed, or non-indexable iterable. -CHB
In short, this has nothing to do with reversed.
I agree.
If you made enumerate return a sequence when its input is a sequence, you would also be able to do enumerate(some_list)[34],
As Chris A mentioned, it's quite easy to wrap list() or tuple() around it if you want that. - Chris B -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython