[Solved] Why list = [0] return false only in first input? [closed]


Pretty crude way of writing the code. But see if this helps in understanding.

Initially:

name = [0]
len(name) = 1

1st iteration

name = [0, "Foo"]
len(name) = 2
name[-2] = 0
if name[-2] => if 0 => False => REPEAT

2nd iteration

name = [0, "Foo", "Foo"]
len(name) = 3
name[-2] = "Foo"       # name[1]
if name[-2] => if "Foo" => True => YOU DID IT => break from the loop

3

solved Why list = [0] return false only in first input? [closed]