list search

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sovixi
    New Member
    • Mar 2007
    • 13

    #1

    list search

    Hi I want the program to search a list for a word and notifiy me if the word exist in the list or no. How can I do it?

    if i use fallowing code:

    finallist1.inde x('high')

    it only returns an index number when word exist in the list and it generates an error if the word is not in the list.

    I want the program to just tell me if the word is or isn't in the list.


    Thanks!!!
  • sovixi
    New Member
    • Mar 2007
    • 13

    #2
    I think I've got the answer:

    check = 'I' in finallist1

    Comment

    • ghostdog74
      Recognized Expert Contributor
      • Apr 2006
      • 511

      #3
      Originally posted by sovixi
      Hi I want the program to search a list for a word and notifiy me if the word exist in the list or no. How can I do it?

      if i use fallowing code:

      finallist1.inde x('high')

      it only returns an index number when word exist in the list and it generates an error if the word is not in the list.

      I want the program to just tell me if the word is or isn't in the list.


      Thanks!!!
      the usual way, is to use "in"
      eg
      Code:
      if "word" in list:
         "blah blah"
      if you want to use index, you can use a try, except block

      Comment

      Working...