Код: Выделить всё
def matching_keys(d: dict[tuple[int, int], int], n: int) -> list[tuple[int, int]]:
"""
find all the keys in a dictionary *d* whose first element is the integer *n*
:param d: the dictionary in question
:type d: dict[tuple[int, int], int]
:param n: the first-element value *n* in question
:type n: int
:return: a list of all the keys whose first elements are *n*
"""
result: list[tuple[int, int]] = []
for x,y in d.keys():
if x == n:
result.append((x,y))
return result
Подробнее здесь: https://stackoverflow.com/questions/798 ... d-property
Мобильная версия