Only a minor, but you could have used `if`, `elif` `else` instead of a 2nd nesting and you have violated PEP-8 -- I do not care about the maximum length per line -- but no space between in list comprehensions.

And: iterators. Yield statement is very useful here, see my next comment.