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 trialAustin Rosales
4,022 PointsRecalling one than one item from a list at a time.
Trying to print all the continents that start with A, but when i do i get TypeError: list indices must be integers or slices, not tuple. So then i tried to print each one at a time ex: print(places[0]) print(places[3]) print(places[5]) print(places[6]) but still says its wrong. feel like i'm missing some small detail, but not sure.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for places in continents:
print("* " + places)
print(places[0, 3, 5, 6])
3 Answers
jhon white
20,006 Pointsfor places in continents:
if 'A' in places[0]:
print("*" + places)
Good luck :)
Jassim Alhatem
20,883 Pointscheck the first index of the string. if it starts with the letter "A" print it.
If you don't get it just reply. and I'll help you out a little more.
Austin Rosales
4,022 Pointsi got it now after i took away from of the [0]. What i was trying was if places[0][0] == 'A': print("* " + places)
Thought [0][0] was looking the the first thing in list followed by first letter, but found out it was just [0].
Austin Rosales
4,022 PointsThought if i did just (Example: places[0]) it would just look at 'Asia' as a whole and not see the 'A'