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 trial

Python Introducing Lists Using Lists Continental

walter fernandez
walter fernandez
4,992 Points

hello i need help with a list

groceries = ['jose',  'app', 'deto']
for i in range(0:3):
      print('*' + groceries[i])
# i need to get the first two name in my list:
#i need this output: * jose
#                               * app

some one, help please.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for i in range(0:3):
print('*'+ continents[i])

2 Answers

Hello, u misunderstood the challange, they want u to use a for loop to loop through each element in the contients array.

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here

#u loop through each elemnt of the contients array
for contient in continents:
#then u want to print each element if the element starts with "A" , u do this by checking if the first index of the element is equal to "A"
    if(contient[0] == "A"):
#if it is we print this element.
        print("* " + contient)
Steven Parker
Steven Parker
229,645 Points

Here's a few hints that may help:

  • arguments should be separated by a comma (,) instead of a colon (:)
  • you should print all the continents, but "range(0,3)" will only print the first 3
  • you don't really need an index, you might use the list itself as the iterable
  • anything that is part of a loop must be indented more than the "for" line
  • add a space after the asterisk to keep it from being right next to the name