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

Python Python Sequences Sequence Iteration Iterating With For Loops

code in lesson not correct

i ended up copying the code in the lesson verbatim and still get an error message.

iterating_lists.py
rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']

for index color in enumerate(rainbow, 1):
    print (f'{index}. {color}')

4 Answers

Michael Hulet
Michael Hulet
47,912 Points

You have not copied this code verbatim. There is still a syntax error, though you're only 1 character off. the enumerate function returns a tuple, so you need to have the tuple be properly unpacked. In your loop, you've written your 2 variables with nothing in between, which is invalid syntax in Python

Thank you but the second challenge isn't mentioned in the treehouse videos. "Edit the code so that the for loop uses the enumerate method. Add a print statement above the existing print statement that prints the index of the current element." I'm considering quitting, this is too agravating, everything makes sense but the workspace drives me insane.

Joshua Lewis
Joshua Lewis
2,107 Points

Just a slight syntax error between index and color, besides that it looks great! Although you didn't need to copy the offset code verbatim.

just get rid off the 1. And separate the print function into two. should be written like this - for index, color in enumerate(rainbow): print(f"{index}. ") print(f"{color}")