Q1: With the map() and filter()
built-ins and the reduce()
function from the functools
module in the standard library
, we can replace many tedious
for
-loops and if
statements. What are some advantages of doing so?
< your answer >
Q2: Looking at the lambda
expression inside reduce() below, what built-in function
is mimicked here?
from functools import reduce
numbers = [7, 11, 8, 5, 3, 12, 2, 6, 9, 10, 1, 4]
reduce(lambda x, y: x if x > y else y, numbers)
< your answer >
Q3: What is the primary use case of list
comprehensions? Why do we describe them as eager?
< your answer >
Q4: generator
expressions may replace list
objects and list comprehensions in many scenarios. When evaluated, they create a lazy generator
object that does not materialize its elements right away. What do we mean by that? What does it mean for a generator
object to be exhausted?
< your answer >
< your answer >
Q6: What is an iterator? How does it relate to an iterable?
< your answer >
Motivate your answer with one short sentence!
Q7: lambda
expressions are useful in the context of the map-filter-reduce paradigm, where we often do not re-use a function
object more than once.
< your answer >
Q8: Using generator
expressions in place of list
comprehensions wherever possible is a good practice as it makes our programs use memory more efficiently.
< your answer >
Q9: Just as list
comprehensions create list
objects, tuple
comprehensions create tuple
objects.
< your answer >