Python Data Structures

Dictionaries

Sets

  • Creating a custom set: The obvious option is to override Collections.set, but this can require a lot of work to override every method. This recipe will allow you to provide a custom equality/uniqueness function. If you want more control, overriding the methods in collections.MutableSet, will provide most methods for free, with the notable exception of update. In older version of Python, the abstract base class collections.Set (which is different from set) was used instead.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License