-2

I'm trying to find an easier way to find one part of a group of strings. Here's what I mean by that:

  word = ["Word", "Palabra"]
  If word == "Word":
    print word

So I need a way to detect if one of the strings equals "Word" without just looking for word[0] or word[1]

levi
  • 22,001
  • 7
  • 73
  • 74

1 Answers1

0

You need to use in.

your_list = ["Word", "Palabra"]    
if "Word" in your_list:
    print "Found!"
    DoSmth()

It means if something is a part of something, return True, return False otherwise.

ForceBru
  • 43,482
  • 10
  • 63
  • 98
  • To be slightly more accurate, I would say "if the sequence contains this element return `True`, else return `False`" – Cory Kramer Mar 05 '15 at 14:25