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

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -