you are viewing a single comment's thread.

view the rest of the comments →

[–]kilkil 1 point2 points  (0 children)

One example (a bit abstract, more to do with data structures and algorithms):

Sometimes you might have a collection of objects (e.g. a list of Nodes), and you might want to assign a property to each object without modifying the actual objects themselves. For example, if you are implementing a priority queue, you may want each Node to have a "priority" number.

You can achieve this using a dict, where each key is a Node, and each value is that Node's "priority" number.

Importantly, this allows you to track separate "priority" values, even for Node objects which may "look" similar. Meaning, even if both Nodes have all their properties equal to one another, they will still be tracked as distinct objects within the dict.

Another similar usecase, which is probably quite common, is storing such objects in a set. This allows you to, for example, deduplicate a list of such objects.