All quizzesHard
Advanced FP Patterns
Preview — 3 of 10 questions
What is the output of the following code?
javascript
factorial = (lambda f: lambda n: f(f, n))(
lambda f, n: 1 if n == 0 else n * f(f, n - 1)
)
print(factorial(5))A5
BTypeError: <lambda>() missing 1 required positional argument
C120
DRecursionError
What is the output of the following code?
javascript
from functools import singledispatch
@singledispatch
def describe(value):
return f"generic: {value}"
@describe.register
def _(value: int):
return f"integer: {value}"
@describe.register
def _(value: str):
return f"string: {value}"
print(describe(42))
print(describe("hi"))
print(describe(3.14))ATypeError: describe() takes 1 positional argument
Binteger: 42, string: hi, generic: 3.14
Cinteger: 42, integer: hi, integer: 3.14
Dgeneric: 42, generic: hi, generic: 3.14
What is the output of the following code?
javascript
from itertools import groupby
data = [1, 1, 2, 2, 1, 3]
sorted_data = sorted(data)
grouped = {key: list(group) for key, group in groupby(sorted_data)}
print(grouped)A{1: [1], 2: [2, 2], 3: [3]}
B{1: [1, 1], 2: [2, 2], 3: [3]}
CKeyError
D{1: [1, 1, 1], 2: [2, 2], 3: [3]}
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.