Re: st...@pearwood.info

> It isn't really well-defined, since enumerate can operate on infinite
> iterators, and you cannot reverse an infinite stream.

It is well defined on any iterable that itself is reversible and has
defined length. For standard types that's lists, strings, dictionary
iterators and some of the collections (deque, dictionary-based counter).


Re: storch...@gmail.com
> Could you please provide evidence that this feature would be quite
> useful? How much usecases can you find in the stdlib?

I needed this while solving a CS problem
https://leetcode.com/problems/container-with-most-water/, which, I agree,
does not tell how useful it is in production projects.

Couldn't find any usecase in stdlib. I could find a usecase in scikit-learn:
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py#L639
in case file gets changed, here is a copy:

for i in reversed(range(len(estimators))):
    name = names[i]
    if name in namecount:
        names[i] += "-%d" % namecount[name]
        namecount[name] -= 1

It can indeed be that one doesn't have to reverse enumeration very
often in practice. It can also be that people just express their ideas
differently knowing it doesn't work in straight-forward way.


Best Regards,
--
Ilya Kamenshchikov
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/W26NX33MDJSDKKEEOWWYFMZN6UKTJUOK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to