May-01-2019, 01:43 PM
(This post was last modified: May-01-2019, 01:43 PM by Divanova94.)
(Apr-30-2019, 04:34 PM)buran Wrote: 30X20 would be 600 elements and you have 3200 (160x20). When you are reshaping, the total number of elements can’t be altered. That is why it works withbreak
- f1 has 30 sub-lists and with brake it takes first element of each so you get 30x20 array to reshape
with the simplified example would you share what desired output would be and how it is achieved
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 = [] def get(f1, f2): for j in f1: for x in j: for i in f2: if i == x: new.append('%s*1' % i) else: new.append('%s*0' % i) return new
Output:['M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*1', 'N1M3*0', 'N1M4*0', 'N1M5*0', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0', 'M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*0', 'N1M3*1', 'N1M4*0', 'N1M5*0', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0', 'M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*0', 'N1M3*0', 'N1M4*1', 'N1M5*0', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0', 'M1N2*0', '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*1', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0']
but the desired output is: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']
How could I get this?