Built-in Functions and Lambdas Flashcards
7 cards from real HACKERRANK practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Built-in Functions and Lambdas flashcards as text
What is the output of `(lambda a, b: a if a > b else b)(10, 20)`?
Answer: 20
The lambda returns the larger of a and b; since 20 > 10, it returns 20.
What does `list(map(str, [1, 2, 3]))` return?
Answer: ['1', '2', '3']
map applies str() to each integer, producing a list of string representations.
What does `bool(0)` return?
Answer: False
bool() converts 0 to False because 0 is falsy in Python.
Which expression using `reduce` from functools computes the product of [1,2,3,4]?
Answer: reduce(lambda x, y: x * y, [1,2,3,4])
reduce applies the multiplication lambda cumulatively: 1*2*3*4 = 24.
What does `type(lambda x: x)` return?
Answer:
A lambda expression creates an anonymous function object, so its type is 'function'.
What is the result of `max([1,2,3], key=lambda x: -x)`?
Answer: 1
key=lambda x: -x negates each value, so max finds the element with the least negative value, which is 1.
What does `list(zip([1,2,3], [4,5]))` return?
Answer: [(1,4), (2,5)]
zip stops at the shortest iterable, so only two pairs are produced.