What is more efficient in terms of memory and speed between
d[(first,second)]
and
d[first][second],
where d is a dictionary of either tuples or dictionaries?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is some very basic test data that indicates that for a very contrived example(storing ‘a’ a million times using numbers as keys) using 2 dictionaries is significantly faster.
Of course, these tests do not necessarily mean anything depending on what you are trying to do. Determine what you’ll be storing, and then test.
A little more data:
Once again this is clearly not indicative of real world use, but it seems to me like the cost of building a dictionary with tuples like that is huge and that’s where the dictionary in a dictionary wins out. This surprises me, I was expecting completely different results. I’ll have to try a few more things when I have time.