storage={}
>>> storage['first']={}
>>> storage['middle']={}
>>> storage['last']={}
>>> storage
{'middle': {}, 'last': {}, 'first': {}}
>>> me='Megnus Lie Hetland'
>>> storage['first']['Megnus']=[me]
>>> storage['middle']['Lie']=[me]
>>> storage['last']['Hetland']=[me]
>>> storage
{'middle': {'Lie': ['Megnus Lie Hetland']}, 'last': {'Hetland': ['Megnus Lie Hetland']}, 'first': {'Megnus': ['Megnus Lie Hetland']}}
>>> my_sister='Anne Lie Hetland'
>>> storage['first'].setdefault('Anne',[]).append(my_sister)
>>> storage['middle'].setdefault('Lie',[]).append(my_sister)
>>> storage['last'].setdefault('Hetland',[]).append(my_sister)
>>> storage
{'middle': {'Lie': ['Megnus Lie Hetland', 'Anne Lie Hetland']}, 'last': {'Hetland': ['Megnus Lie Hetland']}, 'first': {'Anne': ['Anne Lie Hetland'], 'Megnus': ['Megnus Lie Hetland']}}
用了书里面的例子打出的一段代码,很基础,主要是想提醒自己字典的灵活性。