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 trialLEFFLER RAMEY
2,812 PointsI am having trouble calling the list "A" list items in this challenge.
I've tried [0, 3, 5, 6] in different methods, including creating a new list and calling that. I'm genuinely stuck on this portion and can't find any clarification in the video for calling list items by character. Much appreciated!
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for c in continents :
print("* " + c)
2 Answers
jb30
44,807 PointsTo get the first letter of the string c
, you could use c[0]
. You could then compare the first letter to 'A'.
Another way would be to use the startswith
method on your string, such as s.startswith('A')
which will give you either true or false.
LEFFLER RAMEY
2,812 Pointsfor c in continents :
if c[0] == "A"
print("* " + c)
I'm getting syntax error on what I thought would make total sense. Any help here with layout of proper syntax would be much appreciated, this is the first challenge that's left me stuck and i've been thinking on it since yesterday. I may not be built for this, haha.
jb30
44,807 Pointsfor c in continents :
if c[0] == "A":
print("* " + c)
You were missing the colon at the end of your if statement.
LEFFLER RAMEY
2,812 PointsLEFFLER RAMEY
2,812 PointsI'm just stumped here. I tried "if c[0] = "A" " and got a syntax error. We haven't learned anything about the "startswith" method yet. To be clear I have to call continents that start with an 'A' and list them. This exact method hasn't been taught in the video prior to this, I cannot figure a way around this. The hint says "HINT: Remember that you can access characters in a string by index".
jb30
44,807 Pointsjb30
44,807 Pointsc[0] = "A"
tries to assign the value"A"
toc[0]
.c[0] == "A"
compares the values.