for loop - Looping a list through dictionary values python -
i wondering if it's possible loop list of values
example:
lst = ['rh', 'cd241', 'c2', 'sczd9', 'rg59l', 'wnt3a']
through values of dictionary
example:
ref_dict = { '': [''], '6005': ['rh50a', 'cd241', 'slc42a1'], '603': [''], '6000': [''], '8787': ['perrs', 'rgs9l', 'mgc26458'], '41': ['accn2', 'bnac2', 'hbnac2'], '8490': [''], '9628': [''], '5999': ['sczd9'] }
to check if individual value in list has value in dictionary, if have value, return me key in value in.
example : lst value cd241 in dictionary '6005': ['rh50a, cd241, slc42a1']
, return me key "6005"
.
from collections import defaultdict lst = ['rh', 'cd241', 'c2', 'sczd9', 'rg59l', 'wnt3a'] ref_dict = { '': [''], '6005': ['rh50a, cd241, slc42a1'], '603': [''], '6000': [''], '8787': ['perrs, rgs9l, mgc26458'], '41': ['accn2, bnac2, hbnac2'], '8490': [''], '9628': [''], '5999': ['sczd9'] } all_values = defaultdict(list) key in ref_dict: value in (map(lambda x: x.strip(), ref_dict[key][0].split(","))): all_values[value].append(key) print all_values['cd241'] # ['6005']
Comments
Post a Comment