mydict={'f1':'stream','f2':'status','f3':'remarks'}

mydict1={'stream':'RHEL','status':'pass','remarks':'none'}

所需输出
result={'f1':'RHEL','f2':'pass','f3': 'none'}

def function(mydict, mydict1):
    for key,value in mydict1.iteritems():
        print mydict1[key]

最佳答案

使用dictionary comprehension

>>> mydict = {'f1': 'stream', 'f2': 'status', 'f3': 'remarks'}
>>> mydict1 = {'stream': 'RHEL', 'status': 'pass', 'remarks': 'none'}
>>> {key: mydict1[value] for key, value in mydict.items()}
{'f1': 'RHEL', 'f2': 'pass', 'f3': 'none'}

10-01 15:45