your dictionary has 2 types of keys:
- strings like
("S1")
(parenthesis don't make a tuple here, probably the cause of your confusion)
- tuples like
("N1",...)
so querying the dict with just N1
doesn't work because N1
isn't a key, it's a part of some key tuple.
If you want to write it like this for convenience, I'd suggest that you rework it afterwards in a dictionary comprehension:
GScale = {
('S1',) : 'gN', # trailing comma is needed now
('S2',) : 'aN',
('S3',) : 'bN',
('N1','G1','A2','B2') : 'gG',
('N2','G2','A1','B3','C2') : 'aA',
('N3','G3','A3','B1','C3','D2') : 'bB',
('N4','A4','B4','C1','D3','E2') : 'cC',
('N5','B5','C4','D1','E3','F2') : 'dD',
('N6','C5','D4','E1','F3') : 'eE',
('N7','D5','E4','F1') : 'fF'
}
GScale = {k:v for kl,v in GScale.items() for k in kl}
Now GScale
is:
{'N1': 'gG', 'B5': 'dD', 'D4': 'eE', 'C3': 'bB', 'A3': 'bB', 'S3': 'bN', 'F3': 'eE', 'C4': 'dD', 'E3': 'dD', 'D1': 'dD', 'A4': 'cC', 'E2': 'cC', 'G2': 'aA', 'C5': 'eE', 'A2': 'gG', 'N2': 'aA', 'E4': 'fF', 'E1': 'eE', 'D5': 'fF', 'N6': 'eE', 'N7': 'fF', 'B1': 'bB', 'A1': 'aA', 'C1': 'cC', 'F2': 'dD', 'B3': 'aA', 'G3': 'bB', 'F1': 'fF', 'D3': 'cC', 'B2': 'gG', 'B4': 'cC', 'G1': 'gG', 'S1': 'gN', 'C2': 'aA', 'N5': 'dD', 'S2': 'aN', 'N3': 'bB', 'D2': 'bB', 'N4': 'cC'}
now the key/value pairs are expanded and querying any N1
or letter+digit works.
(Note that single value keys have a comma added to make them tuples of 1 element so the iteration on the key tuples in the dictionary comprehension work, not adding the comma will make it appear to work, but it will create keys with individual letters of S1
, S2
...: not what you want)