Python Forum

Full Version: Search for string values in
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
	
arr2 = [x for x in arr if re.search('MINS', str(x), flags=0)]
for item in arr2:
		print(item)
what is your goal? what is your question? elaborate what problem you have.
I'm trying to find multiple values via if conditions as seen below in my code. If either is found in original string array (arr), print out entire string with value. Any help is greatly appreciated, thanks.

	
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)
Hi Guys, I didn't explain well previously. 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 only, 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 Wall .

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)
Why is there a print statement inside a list?
arr2 = [x for x in arr if (re.search('MINS', str(x), flags=0)) or (re.search('NM', str(x), flags=0)) or re.search('min', str(x), flags=0) else x = "No values found" ]
for item in arr2:
    print(item)
Try that. I think thats what you are asking for.
(I've merged the threads. Please don't start a new thread for the same issue.)
Thanks Tannishpage, your solution works, much appreciated
You are welcome. Smile