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 trialStanley Nkosi
4,233 PointsPython Sequence -Task 1 of 2 How to write a loop that iterates over the list provided? Stanley Nkosi
How to write a loop that iterates over the list provided?
rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
for rainbow = colors
for index rainbow in enumerate (colors):
print(f'{'index'}. {rainbow}
Josh Keenan
20,315 Pointsno problem, you can mark this as solved by selecting best answer, happy coding!
1 Answer
Josh Keenan
20,315 PointsHere's my solution:
rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
for i in rainbow:
print(i)
The for loop is what we are using to go over the items in the list. We are needing to output the index of the item in the list and the value i has this. Then we just need to print that out. Hope this makes sense and feel free to ask any questions
Stanley Nkosi
4,233 PointsHi Josh, I did respond last night.All the same thanks a lot.I was battling and I did not know whether I am coming or going.Thanks Josh.
Stanley Nkosi
4,233 PointsStanley Nkosi
4,233 PointsThanks a lot Josh.Your solution was spot on.I can sleep with peace. Stanley Nkosi