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 that code in ipython (with Python 2.7), it gave KeyError: '_[1]'
Does ['_[1]'] mean something special in Python?
locals()['_[1]']is a way to access a reference to list comprehension (or generator) current result inside that list comprehension.It is quite an evil, but can produce funny results:
See more details here: the-secret-name-of-list-comprehensions.