8/39
Part 1 of 7 · Nodes and costsLearn

In Python, a list, a deque or a dict usually does the job

Most of the time, Python already has a better tool than a list you link by hand:

  • A stack: a list, pushing and popping at the end.
  • A queue, or anything added and removed at both ends: collections.deque.
  • Look up by key, in an order you change: a dict, or an OrderedDict.
  • Nodes you link by hand: when the question gives you nodes, or when you hold references to nodes and splice them in and out of the middle.

In an interview, say the first three out loud when they fit. Then write the pointers anyway, because the pointers are what the question tests.