How can i sort the below list of tuples to produce tuples of (3,4) (4,6)
my_list = [(6,4), (3,4)]
I have tried the following
items= [(3,4),(6,4)]
sorted_items= sorted(items)
print(sorted_items)
and
my_list = [(6,4), (3,4)]
my_list.sort(key=lambda tup: (tup[0], tup[1]), reverse=False)
print(my_list)
Thanks
CodePudding user response:
You can use two calls to sorted()
to generate the desired output:
sorted(tuple(sorted(tup)) for tup in my_list)
This outputs:
[(3, 4), (4, 6)]