

> class HashableList ( list ): def _hash_ ( self ): custom_hash = hash ( bool ( self ) and self ) print ( f 'Custom hash for is not a valid key' ) Custom hash for : 99. So you can look here, and our second exception that we got- unhashable type: 'list'. So, what happens if we use one of those mutable data types? Like a list as a key?Ġ2:02 And try to assign it? Oops, I have plural examples.

And even call one of those- no problem! So, remember the restrictions we talked about.Ġ1:41 They can only be used once in a dictionary and keys must also be immutable. And you can see it took those without exception.

And let’s try with a tuple here.Ġ1:25 Go ahead and close this dictionary off. You don’t have to simply use strings or integers- you can use floats, Booleans, even tuples as keys.Ġ1:00 If we open up an example dictionary here and let’s give it a couple of keys of those types.Ġ1:13 There’s a Boolean. You’ve seen so far that you can use values of all sorts in a dictionary. Values, on the other hand, can literally be anything and they can be used more than once.Ġ0:41 Let’s hop into the console for a couple of examples. These are things like integers, floats, strings, Booleans, functions. The keys of the dictionary are not guaranteed to be in any specific order, so trying to reference a value by. If it is used more than once, as you saw earlier, it’ll simply replace the value.Ġ0:19 A key must be immutable-that is, unable to be changed. Because dictionaries are unordered collections. Keys in a dictionary can only be used once. True False False because Its keys can be mutable False because a dictionary is mutable Consider the following two functions and select the correct choice below: The worst case Big Oh time complexity of is worse than re worst case Big Oh time complexity of. But there are a few restrictions I want to briefly talk about. A dictionary is an immutable object because its keys are immutable. 00:00 You’ve seen so far that dictionaries are very flexible, kind of an awesome data type to work with.
