list - What does locals()['_[1]'] mean in Python? -
i saw 1 liner code claimed remove duplicates sequence:
u = [x x in seq if x not in locals()['_[1]']] i tried code in ipython (with python 2.7), gave keyerror: '_[1]'
does ['_[1]'] mean special in python?
locals()['_[1]'] way access reference list comprehension (or generator) current result inside list comprehension.
it quite evil, can produce funny results:
>> [list(locals()['_[1]']) x in range(3)] [[], [[]], [[], [[]]]] see more details here: the-secret-name-of-list-comprehensions.
Comments
Post a Comment