How can I combine equal to and greater than?

Since there are two scenarios in the instructions for which we return the last element of lst1, I used an “or” statement to return lst1[-1] if either scenario evaluated to True, otherwise, return the last element of lst2.

def larger_list(lst1, lst2):
  if len(lst1) == len(lst2) or len(lst1) > len(lst2):
    return lst1[-1]
    return lst2[-1]

Please note that Python and Python3 (and most programming languages) have a build-in operator smaller or equal:<= and larger or equal:>=. They are used very often so it’s good to get well acquainted to these. It makes the code almost half the original length!!! :smiley:
You can replace your if statement to have just one condition as shown below:

 if len(lst1) >= len(lst2): 
       [executed code]

Goodluck with your studies! :slight_smile:

1 Like

Oh boy, I don’t know how I missed that haha. Need more coffee! Thanks!

1 Like