by tomp · 10y ago · 0 comments
[user.first_name for user in table_users if user.is_active]For instance, the SQL query can be parallelized, but not so with the Python list comprehension. If you wanted to create a version that could be run in parallel in Python, you'd have to do it with a map()/filter() construct. Ignoring readability for a sec (pretend it's nice and elegant, like it would be in e.g. Clojure), you are still specifying how the machine should accomplish the goal, not the goal itself.
filter(lambda x: x is not None, map(lambda u: u.first_name if u.is_active else None, table_users))