If elif else statement with a string

Hallo,
may I ask you why this code doesn’t work? The code should return the first sublist of the list.
Any idea?
I tried also without the for loop (I’am not sure if it is necessary), but it always returns the solution “No doors”.

When you’re debugging print out each stage.

You may not be getting what you think.

For example what is ‘i’ in orientation?
You think it’s ‘nord’ but it may not be.

Try a TESTlist.append(i) to see what it is.

If it looks the same check if the input is the same type of data.
Eg, are you trying to match an element with a string or a string with a double.

AH… also noticed your ‘else’ has the wrong indent.

2 Likes


it is the indentation offset of the else (said M. Alien) that transforms your container at the end of your for loop
the doororientation was good then change by assigning the else

cordially
christian.stan

2 Likes

Hi Christian,

Thank you for your example. It works!

BR,

Julia

1 Like

You have a dictionary solution (especially since you only have equals in your choices :wink:) which will also return nul that I don’t know how to remove yet in python

dic_compare={"nord":IN[1][0],"west":IN[1][1],"sud":IN[1][2],"east":IN[1][3]}
container=[]
for i in IN[0]:
    z=dic_compare.get(i)
    container.append(z)
    
OUT = container

edit: OUT = [i for i in container if i is not None]
source
Cordially
christian.stan

1 Like

Thank you for this tip:)

1 Like