A tuple containing a list cannot be used as a key in a dictionary. Answer: True. A list is mutable. Therefore, a tuple containing a list cannot be used as a key in a dictionary.
The Tuple method is similar to the above snippets, and while it is faster than the Dictionary<int, KeyValuePair<string, string>> , it is still nowhere near as fast as indexing directly into the collection to the desired value based on a hashed key, as is done in the MultiKeyDictionary class.
A tuple can contain different values with different datatype while a dictionary can contain only one datatype value at a time. Tuples are particularly useful for returning multiple values from a function. A dictionary can be used as a model object.
A dictionary or a list cannot be a key. Values, on the other hand, can literally be anything and they can be used more than once.
Suppose there is a structure like this:
{'key1' : { 'key2' : { .... { 'keyn' : 'value' } ... } } }
Using python, I'm trying to determine advantages/disadvantages of two different approaches:
{'key1' : { 'key2' : { .... { 'keyn' : 'value' } ... } } } # A. nested dictionary {('key1', 'key2', ...., 'keyn') : 'value'} # B. a dictionary with a tuple used like key
Then I'm interested to know, what is the best (A or B) in terms of:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With