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 trialTapiwanashe Jandura
2,677 PointsHow do I separate particular elements os a list
I want to separate words that start with A only. Please help
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
print("* {}".format(continent))
print(continent[0])
1 Answer
adrian miranda
13,561 PointsYou aren't entirely clear about what you are trying to achieve, but this will print out only the continents that start with "A":
for continent in continents:
if continent[0] == 'A':
print(c)
As you can see, although continent is a string, you can refer to continent[0], which will give you the first character in continent. You could also solve the problem with a regular expression, but that may be overkill for what you are doing.