I have a result like this:
[(196, 128), (196, 128), (196, 128), (128, 196),
(196, 128), (128, 196), (128, 196), (196, 128),
(128, 196), (128, 196)]
And I'd like to convert it to unique values like this, in sorted order:
[128, 196]
And I'm pretty sure there's something like a one-liner trick in Python (batteries included) but I can't find one.
Create the set union of all tuples, then sort the result:
sorted(set().union(*input_list))
Demo:
>>> input_list = [(196, 128), (196, 128), (196, 128), (128, 196),
... (196, 128), (128, 196), (128, 196), (196, 128),
... (128, 196), (128, 196)]
>>> sorted(set().union(*input_list))
[128, 196]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With