Advertisement
ganiyuisholaafeez

Sum function

Feb 29th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. # This function returns the list with the greater sum
  2. def greater_sum(first, second):
  3.     greater = first         # Setting the base of the comparison
  4.     if sum(first) < sum(second): # The condition
  5.         greater = second
  6.     return greater
  7.  
  8. print(greater_sum([1, 2, 3], [1, 2, 4]))
  9. print(greater_sum([4, 5], [2, 6, 3]))
  10. print(greater_sum([1], []))
  11. print(greater_sum([1, 2, 9], [1, 2, 5]))
  12.  
  13. # [1, 2, 4]
  14. # [2, 6, 3]
  15. # [1]
  16. # [1, 2, 9]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement