Well, Uniquify may not be a real word. but the concept we are going to discuss is as real as the ground beneath us !!
With Python 3.6 and above, the order is preserved while inserting keys to a dictionary.
Hence, if you want to find unique elements in a list, here are 2 approaches that are not just fascinating, but are also the fastest.
Approach 1 - Preserving order of sequence
x = [1, 2, 3, 2, 3, 4, 5, 7, 6, 5] print(list(dict.fromkeys(x)))
>>> [1, 2, 3, 4, 5, 7, 6]
Approach 2 - Without preserving the order of sequence
x = [1, 2, 3, 2, 3, 4, 5, 7, 6, 5]
print(list(set(x)))
>>> [1, 2, 3, 4, 5, 6, 7]
Other topics that might interest you.
Do you like what I send you? Then why not help me grow our community?
Share Pydrools with your friends and ask them to join us.
In the meantime, follow Pydrools on twitter.