You know, to turn list:
a = ["hello", "hello", "hi", "hi", "hey"]
into list:
b = ["hello", "hi", "hey"]
You simply do it like this:
b = list(set(a))
It's fast and pythonic.
But what if i need to turn this list:
a = [["hello", "hi"], ["hello", "hi"], ["how", "what"], ["hello", "hi"],
["how", "what"]]
to:
b = [["hello", "hi"], ["how", "what"]]
What's the pythonic way to do it?
>>> a = [["hello", "hi"], ["hello", "hi"], ["how", "what"], ["hello", "hi"], ["how", "what"]]
>>> set(map(tuple, a))
set([('how', 'what'), ('hello', 'hi')])
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