In python... I have a list of elements \'my_list\', and a dictionary \'my_dict\' where some keys match in \'my_list\'.
I would like to search the dictionary and retrieve
Try This:
mydict = {'one': 1, 'two': 2, 'three': 3} mykeys = ['three', 'one','ten'] newList={k:mydict[k] for k in mykeys if k in mydict} print newList {'three': 3, 'one': 1}