Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    PyPython

    Getting started

    • Your first Python program
    • Variables and types
    • Numbers and operators
    • Type conversion and input

    Strings

    • Strings and f-strings
    • String indexing and slicing
    • Cleaning and splitting strings

    Control flow

    • Conditions: if, elif and else
    • Loops: for and while
    • Loop control and nesting

    Functions

    • Functions with def
    • Parameters and scope

    Collections

    • Lists
    • Dictionaries
    • Tuples and sets
    • Comprehensions, enumerate and zip

    Errors, files and libraries

    • Handling exceptions
    • Modules and the standard library
    • Reading and writing files
    • Exchanging data with JSON

    Objects and lazy iteration

    • Classes and objects
    • Inheritance and composition
    • Iterators and generators

    Testing and project

    • Testing and project setup
    • Project: a grade report
    Python

    Collections · Lesson 16 of 25

    Comprehensions, enumerate and zip

    Transform, filter and pair collections.

    8 minutes2 games

    A comprehension builds a new collection: [expression for item in source if condition]. enumerate provides an index and item together; zip pairs corresponding items from iterables.

    Python
    nums = [1, 2, 3, 4]
    print([n * n for n in nums if n % 2 == 0])
    for index, name in enumerate(["Ali", "Mona"], start=1):
        print(index, name)
    print(dict(zip(["Ali", "Mona"], [80, 95])))

    Each item

    Filter condition

    Compute expression

    New collection

    Important

    By default zip stops at the shortest input. Check lengths first when matching every item matters.

    Interview question

    When is a normal loop clearer than a comprehension?

    What's the output?

    print([n + 1 for n in [1, 3] if n > 1])

    What will this code print?

    Exercise

    Print squares of only the even numbers.

    Expected output: [4, 16, 36]

    Python
    nums = [1, 2, 3, 4, 5, 6]
    

    Learn more from

    • Python documentationdocs.python.org
    • Real Python: further readingrealpython.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousTuples and setsNextHandling exceptions
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.