Module 6
Functional Python and Modules
// Lessons
5
// Quiz questions
75
// Reading time
125 min
// Exam length
15 Q
// Coding exercises
9
- 1Lambda Functions & Higher-Order BuiltinsWrite inline anonymous expressions and combine them with map(), filter(), zip(), and sorted(). 20 min 15 questions
- 2Functional Data PipelinesBuild side-effect-free data transformations using pure functions, predicate filters, and functools.reduce. 25 min 15 questions
- 3Modules & Package ArchitectureOrganize multi-file projects, configure namespace imports, and use the __name__ == '__main__' entry point idiom. 25 min 15 questions
- 4Decorators & Function WrappersIntercept and enhance execution behavior using first-class closures, the @ syntax, and functools.wraps. 30 min 15 questions
- 5Generator Expressions & Lazy StreamingProcess large sequence streams with O(1) memory overhead using lazy evaluation syntax. 25 min 15 questions
Coding practice: write it yourself
Real Python, real checks: write your answer, press Run checks, and keep going until it passes. (4 exercises)
Coding practice needs an account. Sign in or create a free ID to run these exercises.
Lab 1: Map squares
Given nums = [1, 2, 3, 4, 5], use map() and a lambda to square each number. Print the resulting list: [1, 4, 9, 16, 25].
Coding Practice is Locked
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.
Lab 2: Filter odd numbers
Given nums = [10, 15, 20, 25, 30], use filter() to keep only odd numbers. Print the resulting list: [15, 25].
Coding Practice is Locked
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.
Lab 3: Sort by price
Given items = [("Pen", 1.5), ("Notebook", 4.0), ("Eraser", 0.5)], sort items by price in ascending order using sorted() and a lambda key. Print: [('Eraser', 0.5), ('Pen', 1.5), ('Notebook', 4.0)].
Coding Practice is Locked
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.
Lab 4: Reduce product
Use functools.reduce and a lambda to calculate the product of [2, 3, 4, 5]. Print: Product: 120.
Coding Practice is Locked
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.
References & Further Reading
Related entries from PyLabs's own reference library.