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
Adding start to enumerate() #47080
Comments
Georg Brandel suggested enumerate() should have the ability to start on I wasn't sure how best to handle a keyword-only argument, so I'd be |
If a start argument gets accepted, it should be positional, not a Besides, METH_O is a lot faster than the alternatives. |
Forget the part about METH_O. That was incorrect. Another idea to order the positional args as ([start,], iterator). for i, element in enumerate(10, iterable):
^-----------------------^
^-------------------------^ |
As it stands, enumerate() already takes a "sequence" keyword as an I agree with you in that my original complaint with the positional |
FWIW, at one point, Guido rejected all variants of the idea. His first |
Note that this functionality is currently available as follows: >>> from itertools import count
>>> list(zip(count(3), 'abcdefg')
[(3, 'a'), (4, 'b'), (5, 'c'), (6, 'd'), (7, 'e'), (8, 'f'), (9, 'g')] The enumerate(itr) builtin is just a convenience to avoid a module The proposed patch would enable the example above to be written more
Or, with the positional argument approach as:
So, more verbose than the existing approach, and ambiguous to boot - as Let's keep the builtins simple, and let itertools handle the variants - |
Mentioning the zip(count(start), itr) version in the enumerate() docs (And of course, in 2.x, it should be izip() rather than zip() to |
So the ambiguity is that enumerate(it, start=N) could be taken as So, I am still in favor of adding a new argument to enumerate(). I'm neutral on the need for a keyword (don't think it would hurt, not
Yes, zip(count(3), seq) is too complex for this simple use case. I've for i, line in enumerat(lines):
i += 1
print "%4d. %s" % (i, line) and variants thereof. |
Okay. I'm against making the argument keyword-only -- IMO keyword-only |
Sure, fine. |
Okay, committed a matching patch in r63208. Thank you all! |
Just discovered this by chance; I would probably have noticed it earlier if the docstring had been updated. Let me know if it needs a new documentation bug ticket and I'll create one. Pretty handy feature by the way, thanks for adding it! |
Created bpo-8635 for the incomplete docstring |
Created bpo-8636 for the broken test cases. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: