|
>>> # User is a class with "email" and "is_active" fields.
... # all_users is a list of User objects.
>>> # Sorted list of active user's email addresses.
... # Passing in a generator expression.
>>> sorted((user.email for user in all_users
... if user.is_active))
['fred@a.com', 'sandy@f.net', 'tim@d.com']
>>>
>>> # Omitting the inner parentheses.
... # Still passing in a generator expression!
>>> sorted(user.email for user in all_users
... if user.is_active)
['fred@a.com', 'sandy@f.net', 'tim@d.com']
|