How to sort list of tuple based on the sum of items in each tuple in Python

1 Answer

0 votes
lst_tpl = [(8, 9), (8, 5, 1), (1, 2, 3), (8, 0), (8, 1)] 
 
lst_tpl  = sorted(lst_tpl, key = lambda i:i[0] + i[1])

print(lst_tpl)

 
 
'''
run:
 
[(1, 2, 3), (8, 0), (8, 1), (8, 5, 1), (8, 9)]
 
'''

 



answered Dec 19, 2019 by avibootz

Related questions

...