I want to format a dictionary for printing (Python 2.7.3), and the dictionary has tuples as keys. With other types of keys I can do
>>> coord = {'latitude': '37.24N', 'longitude': '-115.81W', 'altitude':100}
>>> 'Coordinates: {0[latitude]}, {0[longitude]}'.format(coord)
'Coordinates: 37.24N, -115.81W'
I tried the same but it does not work with tuple keys.
>>> a={(1,1):1.453, (1,2):2.967}
>>> a[1,1]
1.453
>>> 'Values: {0[1,1]}'.format(a)
Traceback (most recent call last):
File "<pyshell#66>", line 1, in <module>
'Values: {0[1,1]}'.format(a)
KeyError: '1,1'
Why? How I can refer to tuple keys in formatting string?
FOLLOW UP
It seems we can't (see answer below). As agf quickly pointed out, Python can't handle this (hope it will be implemented). In the meantime, I managed to refer to tuple keys in format string with the following workaround:
my_tuple=(1,1)
b={str(x):a[x] for x in a} # converting tuple keys to string keys
('Values: {0[%s]}'%(str(my_tuple))).format(b) # using the tuple for formatting