โ† All HACKERRANK Flashcard Decks

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
  1. What does `list(map(lambda x: x ** 2, [1, 2, 3, 4]))` return?

    Answer: [1, 4, 9, 16]

    map applies the lambda squaring function to each element, producing [1, 4, 9, 16].

  2. Which built-in function returns the largest item in an iterable?

    Answer: max()

    max() returns the largest item from an iterable or the largest of two or more arguments.

  3. What is the output of `list(filter(lambda x: x % 2 == 0, range(10)))`?

    Answer: [0, 2, 4, 6, 8]

    filter keeps elements where the lambda returns True, selecting even numbers 0 through 8.

  4. What does `abs(-7.5)` return?

    Answer: 7.5

    abs() returns the absolute value of a number, converting -7.5 to 7.5.

  5. What is the result of `sorted([3,1,4,1,5], reverse=True)`?

    Answer: [5, 4, 3, 1, 1]

    sorted() with reverse=True returns a new list sorted in descending order.

  6. Which of the following correctly uses a lambda with `sorted()` to sort by the second element of each tuple?

    Answer: sorted(lst, key=lambda x: x[1])

    The key parameter accepts a callable; lambda x: x[1] extracts the second element for comparison.

  7. What does `any([False, False, True, False])` return?

    Answer: True

    any() returns True if at least one element in the iterable is truthy.