• Initialize integer as positive or negative infinity: {python} i: int = float('-inf'|'inf')

Collections

Sets

  • Set difference{python} set(list1) - set(list2)
  • Set lookup {python}i in {1, 2, 3}
    • ==Constant time lookup==

List

  • List Sort {python} list2 = sorted(list1)
  • Deduplication{python} list1 = list(set(list1))
  • Counter {python}Counter("mississippi")
    • returns {python}{'i': 4, 's': 4, 'p': 2, 'm': 1}
  • Accumulate{python} accumulate(list1)

Dictionary

  • Default value for dictionary entries{python}dictionary = collections.defaultdict(list|int)
  • Helps when you have a list of dicts, or accumulating a count in a dict.

All conditions true

def is_increasing(lst):
    return all(earlier < later for earlier, later in zip(lst, lst[1:]))
 
# Example usage:
my_list = [1, 2, 3, 4, 5]
print(is_increasing(my_list))  # Output: True