Smooth, remove duplicates and sort list of lists in python

From this answer I have a flattened list.

Now I want to remove duplicates and sort the list. I currently have the following:

x = itertools.chain.from_iterable(results[env].values()) #From the linked answer
y = sorted(list(set(x)), key=lambda s:s.lower())

Is there a better way to do this? In my case, x has a size of ~ 32,000, and y ends with a size of ~ 1,100. I have work, but I would like to see if there is anything better (faster, more readable, etc.)

+4
source share
2 answers

Actually, if you just delete the list (), which is not needed, you have a good neat solution to your original problem. I think your code is well readable and efficient.

y = sorted(set(x), key=lambda s:s.lower())
+3
source

results[env] - , , :

>>> sorted(set().union(*results[env].values()), key=str.lower)

, lambda, str.lower.

+1

All Articles