I’m looking for the best way to Pythonize the: for (int i = 0; i < itemsCount; i++)
Any thoughts?
Thanks in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are iterating over the items in some container, just iterate over that container; don’t use the index unless you need to.
Right:
Wrong (or at least “writing C/C++/Java/C#/whatever in Python”):
If you need an index for some other purpose (e.g. you’re going to modify the container), the Python way is
enumerate():