Embercode
✕
Built-in CollectionsQuick quiz

Ordered lookups with bisect

6 questions. Covers Ordered lookups with bisect.

Questions 1 to 5 of 6

  1. 1. What does this program print, line by line? ``python import bisect keys = [300, 450, 600, 750] print(bisect.bisect_right(keys, 500)) print(keys[bisect.bisect_left(keys, 600) - 1]) print(bisect.bisect_left(keys, 751)) print(keys[bisect.bisect_left(keys, 601)]) ``
  2. 2. What does this program print, line by line? ``python import bisect def count_in_range(keys, lo, hi): return bisect.bisect_right(keys, hi) - bisect.bisect_left(keys, lo) ids = sorted([20, 3, 14, 6, 10]) print('keys in [5, 14]:', count_in_range(ids, 5, 14)) print('keys in [15, 19]:', count_in_range(ids, 15, 19)) print('keys in [1, 30]:', count_in_range(ids, 1, 30)) ``
  3. 3. Which bisect function gives the index where x would go, to the left of any keys equal to x? Give the function name only.

    Type your answer.

  4. 4. For keys = [300, 450, 600, 750], what does bisect.bisect_right(keys, 750) return? Give the number.

    Type your answer.

  5. 5. Why does a dict have no floor or ceiling lookup built in?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.