Skip to content

changed for loop to use enumerate() #1301

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

Merged
merged 3 commits into from
Dec 6, 2017
Merged

Conversation

TheAtomicOption
Copy link
Contributor

enumerate() is cleaner and allows removing an assignment statement.

enumerate() is preferred and usually faster. Inlines an assignment statement.
https://docs.python.org/2.3/whatsnew/section-enumerate.html
@dpkp
Copy link
Owner

dpkp commented Nov 17, 2017

I chose not to use enumerate because the loop explicitly modifies the list itself and that typically doesn't play well with in place iterators

@TheAtomicOption
Copy link
Contributor Author

TheAtomicOption commented Nov 17, 2017

It's not changing the count or order of records just the values, so that shouldn't be an issue in python as the example in the PEP itself shows doing exactly that.

That said, all these build checks failed, which really surprised me since it seemed to work on my clone. The only issue I expected on seeing the code was maybe a performance drag from the change in element size of the data from record --> (record, stuff), but that was there to start with.

@dpkp
Copy link
Owner

dpkp commented Dec 5, 2017

Apologies -- all test fixtures were failing due to an unrelated issue. Please pull latest changes from master and re-run tests.

@TheAtomicOption
Copy link
Contributor Author

Yay it passes, and I am no longer confused! :)

@dpkp
Copy link
Owner

dpkp commented Dec 6, 2017

Thanks for the fixup and link to PEP w/ example!

@dpkp dpkp merged commit 5d1b13e into dpkp:master Dec 6, 2017
@TheAtomicOption TheAtomicOption deleted the patch-1 branch December 6, 2017 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants