Qual é a melhor maneira de criar chaves de tupla intercambiáveis para o mesmo valor de dicionário?
def check():
dict_choice_a = {(a, b) : value, (b, a) : value} #(a, b) and (b, a) refer to the same value but repeted
dict_choice_b = {tuple(sorted((a, b)) : value} #not repetitive but unreadable
dict_choice_a[(a, b)] = new_value #need to do twice to change value but more readable than dict_choice_b
dict_choice_a[(b, a)] = new_value
#value of both keys are always the same
Eu quero criar umdictionary
que possui chaves de tupla referenciadas aos seus valores, essas chaves precisam ser trocáveis conforme(a, b) = (b, a)
e eles se referem apenas ao mesmo valor.
Aqui está a pergunta: qual é a melhor maneira de tornar o elemento de tulpe de chaves intercambiável, mas também se refere ao mesmo valor.
Além disso, a string também deve funcionar na solução.