Ad

I Want Arrange My Second List Of Tuples Into The First List Of Another List Of Tuples

- 1 answer

I want to arrange my second list of tuples into the first list of another list of tuples, while the first list of tuples remains based increasing order based on the second item of each tuple:

1st = [('H', 7)]
2nd = [('I', 5), ('J', 6)]

output

1st = [('I', 5), ('H', 7), ('J', 6)]
Ad

Answer

first = [('H', 7)] 
second = [('I', 5), ('J', 6)]
first = sorted(second + first, key=lambda x: x[1])
print(first)
# [('I', 5), ('J', 6), ('H', 7)]
Ad
source: stackoverflow.com
Ad