Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Get minimum unique tuple pair from list of tuples

$
0
0

Consider the following list of tuples:

transactions = [    ('GBP.USD', '2022-04-29'),    ('SNOW', '2022-04-26'),    ('SHOP', '2022-04-21'),    ('GBP.USD', '2022-04-27'),    ('MSFT', '2022-04-11'),    ('MSFT', '2022-04-21'),    ('SHOP', '2022-04-25')]

I can get the tuple with the minimum date like this:

min(transactions, key=lambda x: x[1])

This returns a single tuple:

('MSFT', '2022-04-11')

I need to return the minimum date of any duplicates along with all unique values. So my output should be this:

[    ('SNOW', '2022-04-26'),    ('SHOP', '2022-04-21'),    ('GBP.USD', '2022-04-27'),    ('MSFT', '2022-04-11'),]

How can I do this?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>