[issue39596] reverse parameter for enumerate()

2020-02-10 Thread Eric V. Smith
Eric V. Smith added the comment: You can already do this using existing composable tools, including: >>> list((item, idx) for idx, item in enumerate(lis)) [('a', 0), ('b', 1), ('c', 2), ('d', 3)] >>> We won't be adding a parameter to enumerate in order add another way of doing this. If you

[issue39596] reverse parameter for enumerate()

2020-02-10 Thread Ammar Askar
Ammar Askar added the comment: What is the use case for this? You seem to want `enumerate` to return (item, index) instead of (index, item) when `reverse=True`? You can achieve this yourself easily a custom generator: >>> def swapped_enumerate(l): ... for idx, item in enumerate(l): ...

[issue39596] reverse parameter for enumerate()

2020-02-09 Thread wyz23x2
wyz23x2 added the comment: A typo in the previous comment: >>> list(enumerate(lis,reverse=True)) [('a',0),('b',1),('c',2),('d',3)] -- ___ Python tracker ___ __

[issue39596] reverse parameter for enumerate()

2020-02-09 Thread wyz23x2
New submission from wyz23x2 : Starting from Python 2.3, the handy enumerate() was introduced. However, I suggest to add a "reverse" parameter: >>> lis = ['a', 'b', 'c', 'd'] >>> list(enumerate(lis)) [(0,'a'),(1,'b'),(2,'c'),(3,'d')] >>> list(enumerate(lis,reverse=True) [('a',0),('b',1),('c',2),(