I do not know what I am missing but I've tried 3 different ways to achieve basically the same thing. Looking at the code below, why does only 1 out of the 4 ways work. I want to see if a value (located in a list) exists inside another list. I checked this SO question but still not understanding why the code is failing to print True1
, True2
, and True4
.
l1 = ["bravo", "alhpa", "charlie"]
l2 = ["alpha"]
if l1[1] in l2:
print "True1" # does not work
if l1[1] == l2[0]:
print "True2" # does not work
if "alpha" in l2:
print "True3" # works
for outer in l1:
for inner in l2:
if outer == inner:
print "True4" # does not work