Good Code
The good version expresses one filter and one transformation in a compact shape.
Lesson 04
Use comprehensions for clear transformations, but switch to loops when branching becomes the main story.
def active_reviewer_emails(users):
return [
user.email.lower()
for user in users
if user.is_active and user.email
]def active_reviewer_emails(users):
emails = []
for user in users:
if user.is_active:
if user.email:
emails.append(user.email.lower())
return emailsThe good version expresses one filter and one transformation in a compact shape.
The bad version spreads a simple collection transformation across nested conditionals, making the main intent harder to see.