Let's say I have 2 dictionaries in Python, like this:
d1 = {}
d2 = {}
d1[(i, j)] = 10
d2[(i, j)] = 20
Instead I could do it like this:
d = {}
d[(i, j)] = (10, 20)
Accessing it could be done with d[(i,j)][0]
and d[(i,j)][1]
.
What I would like to ask is this:
Does the second option need less memory than the first?
If yes, is it half the memory?
I need to use very large dictionaries in a program I am writing and if the second solution is better I would opt for that.
Is it half of the memory?
- Yes.numpy
arrays, which are optimized for matrix style data.