...

/

The Mysterious Key Type Conversion

The Mysterious Key Type Conversion

We'll cover the following...

Let me show you a small magic trick, performed with the Python dictionaries.

Press + to interact
class SomeClass(str):
pass
some_string = 's'
some_dict = {some_string: 42}
print(some_dict.keys())
some_instance = SomeClass('s')
some_dict[some_instance] = 40
print(some_string is some_instance)
print(some_dict) # expected: Two different keys-value pairs
print(some_dict.keys())

Explanation

  • This example is
...

...