i trying figure out how perform following:
firstdictionary = {"firstkey" : "a", "secondkey" : "b"} seconddictionary = {"firstkey" : 3, "secondkey" : 47} emptydictionary = {} key, value in firstdictionary, seconddictionary: # emptydictionary = sort of append method...
so that
seconddictionary = {"a" : 3, "b" : 47}
this quite straight forward. need iterate on 1 of dictionary items , find associated value of second dictionary using key first dictionary.
>>> firstdictionary = {"firstkey" : "a", "secondkey" : "b"} >>> seconddictionary = {"firstkey" : 3, "secondkey" : 47} >>> emptydictionary = {value : seconddictionary.get(key, none) key, value in firstdictionary.items()} >>> print emptydictionary {'a': 3, 'b': 47}
if both dictionaries have same key, replace dict.get construct dictionary indexing
>>> {value : seconddictionary[key] key, value in firstdictionary.items()} {'a': 3, 'b': 47}