-3

I have created two lists in python list1 and list2.

I want to start at the first element in list 1 and search for that element in list 2 if it exists print something, if it does not exist print something else

I'm not sure how to march through list 1 and search list2 for value. I know this will involve a for loop.

for in list1

if values =
print("True")
else:
print("False)
Daniel
  • 5,095
  • 5
  • 35
  • 48
Kris Armstrong
  • 95
  • 1
  • 1
  • 7

1 Answers1

1
for item in list1:
    if item in list2:
        print 'yes'
    else:
        print 'no'
John Gordon
  • 29,573
  • 7
  • 33
  • 58
  • We don't have enough information to know that. OP said _I want to start at the first element in list 1_, which kind of implies that order might be important. – John Gordon Nov 01 '16 at 18:52
  • Again, we don't know that. We don't know what's in list2, nor how it was constructed. In the context of this small example it's not important, but OP might be simplifying. – John Gordon Nov 01 '16 at 19:13
  • Here is the full code. Not quite working correctly. I'm not sure i'm doing my lists correctly as its only comapring the first element. – Kris Armstrong Nov 01 '16 at 19:55
  • I gave you a working example. What else do you need? – John Gordon Nov 01 '16 at 20:01