Python: Referring to a list comprehension in the list comprehension itself?
问题 This thought just came to my mind. Say for whatever reason you wanted to get the unique elements of a list via a list comprehension in Python. [i if i in {created_comprehension} else 0 for i in [1, 2, 1, 2, 3] [1, 2, 0, 0, 3] I dunno, I don't really have a purpose for this but it'd be cool if it was possible to refer to the comprehension as it's being created. (e.g. How to remove duplicate items from a list using list comprehension? is a similar question) 回答1: Disclaimer: this is purely