S
Seoffix.com
Sign In Get Pro Membership

Python Foundations

Python: Fast Data Filtering with List Comprehensions

Beginner Python 25 XP

Python List Comprehensions

List comprehensions provide a concise way to create lists based on existing lists. They are faster and more readable than standard for-loops.

Syntax

[expression for item in iterable if condition]

Example

numbers = [1, 2, 3, 4, 5, 6]
evens = [n for n in numbers if n % 2 == 0]
print(evens) # Output: [2, 4, 6]

Your Task

Given a list of domain names, create a list comprehension that extracts only the domains that end with .com and converts them to lowercase.

Hints

  1. Use d.lower() on each item
  2. Check with .endswith(".com")
  3. Combine into [d.lower() for d in raw_domains if ...]

Your answer

This lesson is checked against the lesson rules. Your code is never run on our servers.

AI Code Explainer & Translator

Runs without any outside service.
 
Mark Complete & Earn XP
Earn 25 XP. Finish every lesson in the track to earn its certificate.
Sign in to earn XP