I saw a one liner code that is claimed to remove duplicates from a sequence:
u = [x for x in seq if x not in locals()[\'_[1]\']]
I tried th
Wow! That's nastily cryptic code. Took a bit of research to find the answer.
Basically the list comprehension is building a new list. It names this temporary list _[1]
. The locals()
part is just using the locals()
dictionary to look up that name, as it's not accessible otherwise. So that line is saying...
[x for x in seq if x not in this_list]
Cryptic.
The found information on this here