I found this on stackoverflow, it does exacly what I was looking for :
>>> k = [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4]]
>>> import itertools
>>> k.sort()
>>> list(k for k,_ in itertools.groupby(k))
[[1, 2], [3], [4], [5, 6, 2]]
I don't understand the list comprehension here. If can't manage to translate it to for iteration
. I always use the following syntax :
[k for k in smthiterable (if condition)]
I tried to change the underscore _
to something else, it still work. But if I remove it, it doesn't. What is it's use?