Python

Tips

  • heapq.heapush 并不保证整体的顺序,只保证满足最小堆规则

code skills

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# nested defaultdict
nested_defaultdict = defaultdict(lambda: defaultdict(int))

# or
dd = defaultdict(dict)

# heapq
class PQ:
  def __init__(self, priority):
    self.priority = priority
  def __lt__(self, other):
    return self.priority < other.priority
  def __eq__(self, other):
    return self.priority == other.priority

create venv

1
python3 -m venv venv

References

Licensed under CC BY-NC-SA 4.0
Get Things Done
Built with Hugo
Theme Stack designed by Jimmy