python - how to save results of two statement without defining extra array -


i comparing 2 arrays in python if statement , elif statement, results should saved in other array, avoid overwriting, using append., have save results of these 2 statement without adding third array! how can append results of if statement elif statement, adhere sequence of occurrence , without defining array!

a = [[[1,20],[2,20],[3,20],[4,20],[5,20],[7,20],[5,20],[9,20],[11,20]]]  b = [[[1,20],[2,20],[3,20],[4,20],[6,20],[7,20],[8,20],[9,20],[10,20]]]  c = []   in range(0,len(b)):   j in range(0,len(b[i])):        if a[i][j][0] == b[i][j][0]:             c.append(b[i][j])        elif a[i][j][0] == 5:              c.append(b[i][j])   print c 

in code defined array "c" save results of if statement , elif statement, need append results of if statement elif statement, without defining array c, , able make print below elif! can me solve issue!?

you use list comprehension process in 1 statement:

>>> = [[[1,20],[2,20],[3,20],[4,20],[5,20],[7,20],[5,20],[9,20],[11,20]]] >>> b = [[[1,20],[2,20],[3,20],[4,20],[6,20],[7,20],[8,20],[9,20],[10,20]]] >>> >>> print([bitem             (aitem, bitem) in zip(a[0], b[0])            if bitem[0] == aitem[0] or aitem[0] == 5] ) [[1, 20], [2, 20], [3, 20], [4, 20], [6, 20], [7, 20], [8, 20], [9, 20]] >>> 

of course does create list, doesn't name it. or store it. or let useful it.

is there reason don't want create new list results?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -