What you have done there is cute and commendable as a mental exercise, but if i'd ever encounter that in production code someone would make a close encounter with my chainsaw. This is basically undebuggable (i don't know the line/statement debuggers python has available, so i'm guessing here at what happens) because either the debugger will step over that in one step because it's one statement, or it'll just keep stepping on the same line again and again which is also entirely useless.
Lastly, what you did there is basically golf the living hell out of that code to bring it down from multiple statement lines to a single one. If i have to reach to such means i might as well use Perl. Only Perl actually does allow me to put multiple statement subs into a lambda, so i don't have to golf there.
Weird days when i have to golf in Python but don't need to in Perl.
In [2] the solution given by yairchu can be written succinctly via generators, which look extremely like a mathematical set definition.
I often happen to think about a problem and explicit it with pen and paper using pure mathematical set notation then implement it in Python.[1] http://stackoverflow.com/questions/1017621/why-isnt-python-v... [2] http://stackoverflow.com/questions/1016997/generate-from-gen...