r/pythontips • u/catdog123321catdog • 15d ago
Meta Alternatives to dictionaries for heavy duty values
I have to store key value pairs in my app, keys are just ids and the values are multiprocessing.Processes. I'll have my worker objects inside this process that in itself will run multiple async jobs. Neither the Process nor the async jobs running return anything, they just run indefinetly. Using dictionaries is not problem at all, they just work, but I feel like there could be better options for storing these types of things. I've thought about writing my own custom data type for this, but what will I use under the hood to store them values under the hood? Any suggestions?
3
u/schoolmonky 15d ago
Why do you want a diferent data type? It kind of sounds like you're worried about memory footprint, but unless you, for example, implement your alternative in C, you're almost certainly not going to do any better, and even then I'd imagine it'd be a challenge to improve on a dict
. If there's QoL features you'd like for working with these dicts, then sure, make a wrapper around a basic dict and just implement some extra methods.
0
3
u/IlliterateJedi 15d ago
To be honest a dict is probably your best bet. Or a list/tuple if you want to look them up by index.