Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Daniel Reis
1,050 Pointswhy add index to the for loop when using enumerate?
I just want to double check I'm not doing anything wrong
Ashley wrote:
for index, item in enumerate(groceries, 1): print(f'{index}. {item}')
I wrote it differently as I got confused with the way it was written. I don't understand why one needs to add index to the for loop? So I wrote
for item in enumerate(groceries, 1): print(item)
The result was the same. Have I missed something?
2 Answers
Mohammad Azawi
Courses Plus Student 5,631 PointsNo, the are not .
Ashley's code unpack the tuple and print out individual variables.
and you code print out a tuple pairs.
Daniel Reis
1,050 PointsHow embrassing... my bad.
Mohammad Azawi
Courses Plus Student 5,631 PointsIt is okey. we all been and still in your place.
Good luck :))