Python Code Challenges: Lists - 2. Larger List
why do I get syntax error with this code:

def larger_list(1st,2nd):
  if len(1st) > len(2nd):
    return 1st[-1]
  if len(2st) > len(1st):
    return 2nd[-1]
  elif return 1st[-1]

your elif:

elif return 1st[-1]

doesn’t have any condition. Besides, why would you want to use elif here?

But why do I have:

 File "", line 2
    def larger_list(1st,2nd):
SyntaxError: invalid syntax

right? I can change it to else? but that’s not the main problem

Because variable names can’t start with a number. If variable start with number, making distinction between integer and variables becomes a lot more difficult

1 Like

Really? thanks! I thought it was 1st here:
Write a function named larger_listthat has two parameters namedlst1andlst2 .

lst1 is something very different from 1st.

lst1 starts with the consonant l (like Lima), not a number.

I myself have stepped into that when I started coding at codecademy. I think they just change this lst1 and lst2 naming to something else.
By convention python says that we SHOULD NOT use l (small case L) and I (captial case I) for naming objects (just the letter or maybe at the beginning of the name) as they can be misinterpreted as 1.

P.S. you can see that they both (l and I) look similar here too!

1 Like

Can I see the documentation on this? I am curious for the exact wording/phrasing.

This was released in PEP 8 Style Guide for python

Here is the link for the PEP 8 Style Guide page.
Here is the link for the exact paragraph.


Note that the exact working indicates only single character variable names (like l, O, or I). The documentation doesn’t specify that multi-character variable names, starting with l, O, or I, aren’t recommended.

Because using l, O, and I at the beginning of a variable name can be a bit confusing, the documentation itself recommends using L instead of l if necessary.

1 Like

Yes I know that and that’s exactly what I meant!

1 Like