Skip to content
Advertisement

Sort the list of tuples in python

I have tuples like this

JavaScript

these are the coins and its expiries. The date is in string format, so the arrangement is wrong.

so i have changed the format to date and tried to arrange. I have tried the below code.

JavaScript

and the result is as expected as sorted.

JavaScript

now when i want back in older format which i mentioned in string, its not in the same order. It goes into unsorted way. Need help in making in sorted way in string format at the end.

Advertisement

Answer

Sort by the coin and the date using datetime.datetime:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement