Is it possible/safe to assign back to the same variable when using dictionary comprehension?

Viewed 20

I have the following statement:

catalog = {k: v for k, v in catalog.items() if predicate(v)}

which is using the very same variable left side what is referenced in the dictionary comprehension in right side.

(I do not know what of the comprehension execution is doing in place, what are the iterator(s) yielding and if there are some lazy eval behind the scenes, so having wild fantasy I can imagine that the dictionary is corrupting because some iteration is modifying the subject of iteration.)

Question

Is the statement above is guaranteed to be safe for some reason, or just avoid for it?

0 Answers
Related