Well, that question may not have an answer if the values are not unique; for example, if
book['key1'] = {'keya':valuea, 'keyb':valueb}
and
book['key2'] = {'keya':valuec, 'keyd':valued}
then 'keya' cannot be mapped backwards.
But suppose that your values
are unique. Then you could do this:
>>> import shelve ## set up an example
>>> f= shelve.open("mydatabase")
>>> f['one'] = {1:2,3:4}
>>> f['two'] = {5:6,7:8}
>>> f.close()
>>> revdict = {} ## Here's the reverse lookup code
>>> for key in f.keys():
for subkey in f[key]:
revdict[subkey] = key
>>> revdict
{1: 'one', 3: 'one', 5: 'two', 7: 'two'}
Basically, you're just reversing a dictionary. But again, you must be mathematically certain that your values are unique; else, you'll clobber things.
Jeff