Skip to main content

Tools

These tools are Python specific. To see JavaScript equivalent click here.

Imports

from bisect import bisect_left, bisect_right, insort
from collections import Counter
from functools import cache
from itertools import accumulate, combinations, permutations
from math import atan2, comb, inf
from sortedcontainers import SortedList

Usage

# Prefix sum
p = [0] + list(accumulate(nums))

# Four adjacent directions
[[dx, dy] for dx, dy in itertools.permutations([-1, 0, 1], 2) if abs(dx) != abs(dy)]

match

match param:
case first:
pass
case second:
pass
case _:
pass

math

rad = math.atan2(y2 - y1, x2 - x1)
deg = rad * math.pi / 180

sortedcontainers

SortedList

sortedList = SortedList()
sortedList.add((num1, num2, num3))
sortedList.remove((num1, num2, num3))