Python loop through lists and append according to conditions -


i have 3 lengthy lists (of length 15,000). lets example 3 lists are:

a    b    c 0    2    3 0    4    5 0    3    3 1    2    6 1    3    5 0    2    7 1    8    8 

i values of b , c corresponding index of 0. example if a[i] == 0 add b[i] listb_0 , c[i] listc_0.

i tried

listb_0 = [] listc_0 = []  a,b,c in zip(a,b,c):     if == 0:         listb_0.append(b)         listc_0.append(c) 

but seems put python through never ending loop, after 5 minutes, see program still running.

what want is, example listb , listc lista = 0 be

listb_0 = [2,4,3,2] listc_0 = [3,5,3,7]  

what correct way achieve this?

brobin pointed out in comment: instead of b or c, whole lists b or c appended.

this should work:

a = [0, 0, 0, 1, 1, 0, 1] b = [2, 4, 3, 2, 3, 2, 8] c = [3, 5, 3, 6, 5, 7, 8]  listb_0 = [] listc_0 = []  a, b, c in zip(a,b,c):     if == 0:         listb_0.append(b)         listc_0.append(c)  print listb_0 print listc_0  >>>  [2, 4, 3, 2] [3, 5, 3, 7] 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -