#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    21
    Rep Power
    0

    Unhappy Search for multiple string values in array


    Hi Guys, I'm trying to find specific string if available in a string array via if conditions as seen below in my code.

    The current code doesn't work, but will only work for the 1st if statement, without other elif and else statements. This is what I'd like to achieve, if any of the strings found in if conditions found in original string array (arr), print out entire string with string value searched for.

    Any help is greatly appreciated, thanks .

    Code:
    arr2 = [x for x in arr 
    if re.search('MINS', str(x), flags=0) 
    eif re.search('NM', str(x), flags=0) 
    eif re.search('min', str(x), flags=0) 
    else print("No values found" ]
       for item in arr2:
        print(item)
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,951
    Rep Power
    509
    Untested:
    Code:
    # >>> [i for i in range(20)if i%2]  warm up.  Stretch before you exercise.
    
    
    arr2 = [x for x in arr if
        re.search('MINS', str(x), flags=0)
     || re.search('NM', str(x), flags=0) 
     || re.search('min', str(x), flags=0)]
    
    if not arr2:
        print("No values found")
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    21
    Rep Power
    0
    Thanks b49P23TIvg, your solution works, short and sweet, cheers

IMN logo majestic logo threadwatch logo seochat tools logo