I have basically a list of all the files in a folder, which in a simplified version looks like :
file_list = [ 'drug.resp1.17A.tag', 'drug.resp1.96A.tag', 'drug.resp1.56B.tag', 'drug.resp2.17A.tag', 'drug.resp2.56B.tag', 'drug.resp2.96A.tag']
Another list :
drug_list = [ '17A', '96A', '56B']
I want to combine these two list into a dictionary, such that:
dictionary = {
'17A' : ['drug.resp1.17A.tag' , 'drug.resp2.17A.tag' ],
'96A' : ['drug.resp1.96A.tag' , 'drug.resp2.96A.tag' ],
'56B' : ['drug.resp1.56B.tag' , 'drug.resp2.56B.tag' ]}
I thought of doing like this but got stuck !
dict_drugs = {}
for file in file_list:
list_filename = file.split('.')
for elem in drug_list:
if elem in list_filename:
What can I do after this to join the elements into a dictionary, or am I doing this completely wrong ?
well you don’t need inner loop
one more check if only needs those values that are present in drug_list
means if file_list contains :
file_list = [ ‘drug.resp1.18A.tag‘, ‘drug.resp1.96A.tag’, ‘drug.resp1.56B.tag’, ‘drug.resp2.17A.tag’, ‘drug.resp2.56B.tag’, ‘drug.resp2.96A.tag’]
One more way to efficently do upper case: