
Re: steve@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: storchaka@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... 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
participants (1)
-
Ilya Kamenshchikov