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

No idea how to do that...

hows that thing is done

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for continent in continents:
    print(continent)

What is your question about? I cannot understand you question, sorry.

I have done the printing part with bullet.. problem was next challenge.. where it says "I'd like you to now only print continents that begin with the letter "A". HINT: Remember that you can access characters in a string by index"

Now I don't know how to do that, even a hint is not reminding me.. it was some thing like print[] but how it will filter the continent starting with A.

sorry I was not clear initially as I am new to this and thought, If I share even the question in challenge will be shared..

Awaiting for help

2 Answers

I found that the trick here is understanding the naming of the for loop

The for and the in are always the same. They are Python keywords.

for whatever_you_name_me in an_existing_sequence:
    print(whatever_you_name_me)

^^^ this could be your template

It is a convention to name the whatever_you_name_me so it reflects what is inside the sequence you are looping over.

In your example, the sequence is a list of continents. This is why the variable is called continent. The loop goes through the whole sequence, grabs each element of the list, which is called continent every time, but it refers to a new element of the sequence each time it loops. Than in the indented body you do sth. In this case, you print the name.

This would work the same way and be just fine for Python:

for yellow_dragon in continents:
    print(yellow_dragon)

but it would not look nice because it does not make it easy for the human reading the code.

Exacte'mondo.

The base format is the: for _ in _ : NB the ' : ' do something

later you will learn how to do different and more complex things. It is really nice.

Do you have trouble understanding the for loop concept?

If so. The for loop goes over every item (in your case continent) in a list (continents). For every item, the loop does something. In your case, print the item. So the loop lopes 7 times though your list.

Good luck;)