Larger sum (Python Code Challenges: Loops (Advanced))

“The body of this function could also be condensed into one line of code if you want an additional challenge!”

How can we code the body of this function in one line?

def larger_sum(lst1, lst2):

  if sum(lst1) >= sum(lst2):

    return lst1

  return lst2

Only solution I see is to use a ternary operator

1 Like
def larger_sum(lst1, lst2):
  return lst1 if sum(lst1)>=sum(lst2) else lst2