0
Using tuples as key in dict
What is a practical application of why you would use a tuple (especially larger tuples) as a key in a dictionary?
1 Answer
+ 2
I don't know many purposes for using large tuples as dictionary key, but I may know one.
If you have a slow function and a high likelihood to call the function multiple times with the same values it can be good idea to put the function arguments in tuple and use the tuple as a dictionary item key and the function return value as the dictionary item value. Then you will be able to use the dictionary as a function for the values you have already calculated.
...
I don't really know where it would be useful, because having too many items in a dict can also cause problems.
Anyways here is an example:
https://code.sololearn.com/c4mnJTryt0my/?ref=app