Assignment in python for loop possible?

Posted by flyingcrab on Stack Overflow See other posts from Stack Overflow or by flyingcrab
Published on 2010-06-18T01:22:12Z Indexed on 2010/06/18 1:33 UTC
Read the original article Hit count: 563

Filed under:
|

I have a dictionary d (and a seperate sorted list of keys, keys). I wanted the loop to only process entries where the value is False - so i tried the following:

for key in keys and not d[key]:
 #do foo

I suppose my understanding of python sytax is not what i thought it was - because the assignment doesnt suppose to have happened above, and a i get an instanciation error.

The below works of course, but I'd really like to be able to use something like the code above.. possible?

for key in keys:
 if d[key]: continue
  #foo time!

Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about syntactic-sugar