May-01-2019, 03:01 PM
(This post was last modified: May-01-2019, 03:01 PM by Divanova94.)
(May-01-2019, 02:10 PM)buran Wrote: still not sure I understand, but this will produce the desired result. requires python 3.6+f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5']] f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5'] new = [] for item in f2: for sub_list in f1: new_item = f'{item}*{int(item in sub_list)}' new.append(new_item) print(new)
Thank you very much, but in case with two lists in f1
f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5'], ['M1N2', 'N2M3', 'N2M4', 'N2M5']] f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5'] new = [] for item in f2: for sub_list in f1: new_item = f'{item}*{int(item in sub_list)}' new.append(new_item) print(new)It will give the output:
Output:['M1N2*0', 'M1N2*1', 'M1N3*0', 'M1N3*0', 'M1N4*0', 'M1N4*0', 'M1N5*0', 'M1N5*0', 'M2N3*0', 'M2N3*0', 'M2N4*0', 'M2N4*0', 'M2N5*0', 'M2N5*0', 'M3N4*0', 'M3N4*0', 'M3N5*0', 'M3N5*0', 'M4N5*0', 'M4N5*0', 'N1M2*1', 'N1M2*0', 'N1M3*1', 'N1M3*0', 'N1M4*1', 'N1M4*0', 'N1M5*1', 'N1M5*0', 'N2M3*0', 'N2M3*1', 'N2M4*0', 'N2M4*1', 'N2M5*0', 'N2M5*1', 'N3M4*0', 'N3M4*0', 'N3M5*0', 'N3M5*0', 'N4M5*0', 'N4M5*0']
But I need this output:Output:['M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*1', 'N1M3*1', 'N1M4*1', 'N1M5*1', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0']
['M1N2*1', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*0', 'N1M3*0', 'N1M4*0', 'N1M5*0', 'N2M3*1', 'N2M4*1', 'N2M5*1', 'N3M4*0', 'N3M5*0', 'N4M5*0']