class Key:
def __init__(self, value):
self.value = value
def __eq__(self, other):
if isinstance(other, Key):
return self.value == other.value
return False
def __hash__(self):
return hash((type(self), self.value))
my_dict = {Key('key'): 'value'}
print(my_dict[Key('key')])
from typing import Dict
my_dict: Dict[str, int] = {'one': 1, 'two': 2}
print(my_dict['one'])
def my_dict_func(my_dict: dict[str, int]) -> int:
return my_dict['one']
print(my_dict_func({'one': 1, 'two': 2}))
标签: 兼职