pyrsistent.PMap and PRecord may be worth a look: https://pyrsistent.readthedocs.io/en/latest/api.html#pyrsistent.PMap :
> Persistent map/dict. Tries to follow the same naming conventions as the built in dict where feasible. > > Do not instantiate directly, instead use the factory functions m() or pmap() to create an instance. > > Was originally written as a very close copy of the Clojure equivalent but was later rewritten to closer re-assemble the python dict. This means that a sparse vector (a PVector) of buckets is used. The keys are hashed and the elements inserted at position hash % len(bucket_vector). Whenever the map size exceeds 2/3 of the containing vectors size the map is reallocated to a vector of double the size. This is done to avoid excessive hash collisions. > > This structure corresponds most closely to the built in dict type and is intended as a replacement. Where the semantics are the same (more or less) the same function names have been used but for some cases it is not possible, for example assignments and deletion of values. > > PMap implements the Mapping protocol and is Hashable. It also supports dot-notation for element access. > > Random access and insert is log32(n) where n is the size of the map. ... https://pyrsistent.readthedocs.io/en/latest/intro.html#pyrsistent : > Pyrsistent is a number of persistent collections (by some referred to as functional data structures). Persistent in the sense that they are immutable. > > All methods on a data structure that would normally mutate it instead return a new copy of the structure containing the requested updates. The original structure is left untouched. > > This will simplify the reasoning about what a program does since no hidden side effects ever can take place to these data structures. You can rest assured that the object you hold a reference to will remain the same throughout its lifetime and need not worry that somewhere five stack levels below you in the darkest corner of your application someone has decided to remove that element that you expected to be there. > > Pyrsistent is influenced by persistent data structures such as those found in the standard library of Clojure. The data structures are designed to share common elements through path copying. It aims at taking these concepts and make them as pythonic as possible so that they can be easily integrated into any python program without hassle. On Wed, Jul 22, 2020, 12:28 PM Guido van Rossum <gu...@python.org> wrote: > Did you study PEP 416 (frozendict) and PEP 603 (frozenmap)? > > -- > --Guido van Rossum (python.org/~guido) > *Pronouns: he/him **(why is my pronoun here?)* > <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/> > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/F6KFQX5CKEUNKLZQGALTEROAP3PHOSPW/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/BSIBL3KFXQDEOWZIE3F5WTXD5NYFNLXY/ Code of Conduct: http://python.org/psf/codeofconduct/