Zunächst sind das Wörterbücher und keine Listen. Außerdem kenne ich Ihre Absicht nicht, zwei Wörterbücher in dieser Darstellung zusammenzuführen.
Auch immer, wenn Sie die Ausgabe wollen genau zu sein, wie Sie erwähnt haben, dann ist dies der Weg, es zu tun -
BIG = { "Brand" : ["Clothes" , "Watch"], "Beauty" : ["Skin", "Hair"] }
SMA = { "Clothes" : ["T-shirts", "pants"], "Watch" : ["gold", "metal"],"Skin" : ["lotion", "base"] , "Hair" : ["shampoo", "rinse"]}
for key,values in BIG.items(): #change to BIG.iteritems() in python 2.x
newValues = []
for value in values:
if value in SMA:
newValues.append({value:SMA[value]})
else:
newValues.append(value)
BIG[key]=newValues
Auch BIG.update(SMA)
werden Sie nicht die richtigen Ergebnisse geben in der Art und Weise Sie wollen, sein.
Hier ist ein Testlauf -
>>> BIG.update(SMA)
>>> BIG
{'Watch': ['gold', 'metal'], 'Brand': ['Clothes', 'Watch'], 'Skin': ['lotion', 'base'], 'Beauty': ['Skin', 'Hair'], 'Clothes': ['T-shirts', 'pants'], 'Hair': ['shampoo', 'rinse']}
Mögliche Duplikat (http://stackoverflow.com/questions/38987/how-to -merge-two-python-dictionaries-in-single-expression) –
'BIG.update (SMA)' –