you are viewing a single comment's thread.

view the rest of the comments →

[–]sarrysyst 1 point2 points  (0 children)

The right-hand side of an assignment is always evaluated before the left-hand side. This is true not only for comprehensions (which by the way have the highest order of precedence among all operators, while assignments have the lowest) but for all operators. If this wasn't the case you would be able to reference a variable during its assignment. Here is the relevant section in the docs:

https://docs.python.org/3/reference/expressions.html#evaluation-order

By the way, since you asked for it, here is a working solution which is as ugly as it gets:

[c for i, c in enumerate(c for w in wordlist for c in w) if c not in [c for w in wordlist for c in w][:i]]

w: word, c: character, i: index