Conditional evaluation of several lists in Python

python
#1

Hi,

How can several lists be evaluated in Python?

For instance this works for one list:

dataEnteringNode = IN[0]
c=[]

for i in IN[0]:
if i == “aaa”: c.append(“is aaa”)
elif i == “bbb”: c.append(“is bbb”)
elif i == “ccc”: c.append(“is ccc”)
else: c.append(“is none”)
OUT = c

But if I want to enter several lists in the Python code and compare elements from several lists, something like:

dataEnteringNode0 = IN[0]
dataEnteringNode1 = IN[1]
dataEnteringNode2 = IN[2]
c=[]

for i in IN[0] and j in IN[1]:

_ if i == “aaa” and j ==“aaa”: c.append(“is aaa”)_
_ elif i == “bbb” and j !=“ccc”: c.append(“is bbb”)_
_ elif i == “ccc”: c.append(“is ccc”)_
_ else: c.append(“is none”)_

OUT = c

Please, can anybody clarify?

Thanks

#2

This could help:

#3

Not exactly what I’m asking but thanks, it’s good to know.

#4

just look at the zip function. You can zip also more than 2 lists, but they need to have the same lengh

looks like that

a =in[0]
b =in[1]

for h,g in zip(a,b)
do something()

or one “for loop” in another

for a in lista:
___…
___for b in listb
______…

1 Like
#5

@Fiesta
You beat me to it :slight_smile:
Anyway here’s an exaple:

2 Likes
#6

Wow, that’s great! Thanks both :slight_smile: