Is there a simple way to detect the last iteration while iterating over a dictionary using iteritems()?
Is there a simple way to detect the last iteration while iterating over a
Share
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.
This is a special case of this broader question. My suggestion was to create an enumerate-like generator that returns -1 on the last item:
Add
gen = iter(gen)if you want it to handle sequences as well as generators.