Python Introducing Lists Using Lists Continental

Olivier Jean-Francois
Olivier Jean-Francois
689 Points

I'd like you to now only print continents that begin with the letter "A".

I noticed there already is an answer to the question, however i still want to know why my code is wrong. It keeps skipping over the first value in continents(Asia)?

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for continent in continents:
    first_index = (continent[0:1:1]).lower()
    if first_index == "a":
        print(continent)

2 Answers

Rune Andreas Nielsen
Rune Andreas Nielsen
5,341 Points

Hi Olivier,

The reason that your code is not doing is expected is because you're checking for the lowercase 'a' instead of uppercase 'A'.

The underlying value of lowercase 'a' and uppercase 'A' is different therefore your conditional statement is not executing as you might expect it to. If you want to know more about why this is happening you can read into UNICODE and ASCII characters.

https://docs.python.org/3/howto/unicode.html

// Rune