bisect: list of tuple
β’ 64 words β’ 1 min
a = [(1, 3), (1, 4), (2, 5), (3, 6), (3, 7), (5, 8)]
b = [1, 1, 2, 3, 3, 5]
c = [x for (x, _) in a]
assert b == c
import bisect
assert bisect.bisect_right(b, 1) == 2
assert bisect.bisect_right(b, 3) == 5
assert bisect.bisect_right(b, 6) == len(b)
## use:
## i = bisect.bisect_right(b, 3)
## return a[i - 1][1]
Related Posts
LeetCode #23: Merge k Sorted Lists:
Heap of ListNodes:
python import heapq # Definition for singly-linked list. # class ListNode: # def __init__(self, β¦
Jan 15, 2026
LeetCode #203: Remove Linked List Elements:
python # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # β¦
Dec 31, 2025
Previously, previously, previously, previously, previously.
Thiago Perrotta