
I have on a few occasions wanted a for..in..if statement and if it existed would have used it. However, I agree that the level of change a new statement type brings to the language is probably too high for this feature. But what if python lifted the newline requirement for blocks that contain compound statements? That is, statements that end in a ':' can be followed by other statements that end in a ':' on the same line. AFAICT there would be no ambiguity (to the parser; to humans, depends). Doing so would add the OPs requested feature, though it would be two statements on one line with one extra character. It would also essentially bring the full comprehension syntax to for loops since fors and ifs could be chained arbitrarily. # for..if for x in y: if x in c: some_op(x # nested generator-like for for line in doc: for word in line.split(): spellcheck(word) # side effect one-liner for item in an_iterable: if condition(item): side_effect(item)) Regards, Jeremiah