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 = [
    'South America',
    'North America',
# Your code here
for continent in continents:
    first_index = (continent[0:1:1]).lower()
    if first_index == "a":

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.

// Rune