Preplp
Daily Python
Day 13Python~35 min

List comprehensions

Compact loops for transforms and filters

Track progress0/15 days
x

What you'll learn

list comprehensionconditional expressionzip
  • Build lists in one line with comprehensions
  • Assign letter grades from scores

Lesson & examples

Read the code, then the explanation — try changing values before the project.

Filter evens
numbers = [1, 2, 3, 4, 5, 6]
evens = [x for x in numbers if x % 2 == 0]

Today's exercise: Student Grade Manager

Parse scores, assign grades, list passing and failing students.

Steps

  1. 1

    Parse scores

    Split comma-separated input into ints.

  2. 2

    Grades list comp

    Map scores to A–F with nested conditionals.

Full project source — copy into a folder or use the zip above

starter.py
raw = input("Enter scores (comma-separated): ")
scores = [int(s.strip()) for s in raw.split(",") if s.strip()]

grades = [
    "A" if s >= 90 else "B" if s >= 80 else "C" if s >= 70 else "D" if s >= 60 else "F"
    for s in scores
]

passing = [s for s in scores if s >= 60]
failing = [s for s in scores if s < 60]

for i, (s, g) in enumerate(zip(scores, grades), 1):
    print(f"Student {i}: {s} ({g})")
print("Passing:", passing)
print("Failing:", failing)

One rehearsal platform

Certification mocks, daily lessons, project labs, and in-browser drills

Structured for exam day and portfolio proof — timed tests, guided builds, and quick reps on one platform.