Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverse parameter for enumerate() #83777

Closed
wyz23x2 mannequin opened this issue Feb 10, 2020 · 4 comments
Closed

reverse parameter for enumerate() #83777

wyz23x2 mannequin opened this issue Feb 10, 2020 · 4 comments
Labels
3.9 only security fixes build The build process and cross-build type-feature A feature request or enhancement

Comments

@wyz23x2
Copy link
Mannequin

wyz23x2 mannequin commented Feb 10, 2020

BPO 39596
Nosy @ericvsmith, @ammaraskar, @wyz23x2

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-02-10.09:24:03.120>
created_at = <Date 2020-02-10.07:35:43.117>
labels = ['type-feature', '3.9', 'build']
title = 'reverse parameter for enumerate()'
updated_at = <Date 2020-02-10.09:24:03.116>
user = 'https://github.com/wyz23x2'

bugs.python.org fields:

activity = <Date 2020-02-10.09:24:03.116>
actor = 'eric.smith'
assignee = 'none'
closed = True
closed_date = <Date 2020-02-10.09:24:03.120>
closer = 'eric.smith'
components = ['Build']
creation = <Date 2020-02-10.07:35:43.117>
creator = 'wyz23x2'
dependencies = []
files = []
hgrepos = []
issue_num = 39596
keywords = []
message_count = 4.0
messages = ['361670', '361671', '361674', '361676']
nosy_count = 3.0
nosy_names = ['eric.smith', 'ammar2', 'wyz23x2']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue39596'
versions = ['Python 3.9']

@wyz23x2
Copy link
Mannequin Author

wyz23x2 mannequin commented Feb 10, 2020

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),('d',3)]
>>>

@wyz23x2 wyz23x2 mannequin added 3.9 only security fixes build The build process and cross-build type-feature A feature request or enhancement labels Feb 10, 2020
@wyz23x2
Copy link
Mannequin Author

wyz23x2 mannequin commented Feb 10, 2020

A typo in the previous comment:
>>> list(enumerate(lis,reverse=True))
[('a',0),('b',1),('c',2),('d',3)]

@ammaraskar
Copy link
Member

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):
...     yield item, idx
...
>>> list(swapped_enumerate(lis))
[('a', 0), ('b', 1), ('c', 2), ('d', 3)]

@ericvsmith
Copy link
Member

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 really want to pursue this, you should discuss it on the python-ideas mailing list and try to get the idea accepted there. But it really doesn't have any chance of being accepted.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes build The build process and cross-build type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants