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 triala a
1,101 Pointscode challenge question
I have trouble in shopping list challenge. https://teamtreehouse.com/library/python-basics/shopping-list-app/continue So I make a simple code installing anaconda to make it clear and I have a question now.
items = ["abc", "xyz"] for item in items: print(item) abc xyz
items[0] "abc"
item[0] "x"
why item[0] = "x"? I thought item[0] = "a".
1 Answer
Steven Parker
231,236 PointsSo item[0] would be "a" during the first pass through the loop.
But on the second (and last) pass, "item" was set to "xyz". So at that point, item[0] is "x".
MING JIA
1,280 PointsMING JIA
1,280 PointsYou are you confused item with items, item is an iterator end up to be 'xyz' . in the last loop, and item[0] == 'x' you can replace all 'item' to 'individual_string' to be clear.