Q:

Sort a tuple of tuples by 2nd item using python programming

belongs to collection: Python Tuple Exercises

0

Sort a tuple of tuples by 2nd item

Given:

tuple1 = (('a', 23),('b', 37),('c', 11), ('d',29))

Expected output:

(('c', 11), ('a', 23), ('d', 29), ('b', 37))

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

tuple1 = (('a', 23), ('b', 37), ('c', 11), ('d', 29))
tuple1 = tuple(sorted(list(tuple1), key=lambda x: x[1]))
print(tuple1)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Counts the number of occurrences of item 50 from a... >>
<< Given is a nested tuple. Write a program to modify...