Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search for string values in
#1
	
arr2 = [x for x in arr if re.search('MINS', str(x), flags=0)]
for item in arr2:
		print(item)
Reply
#2
what is your goal? what is your question? elaborate what problem you have.
Reply
#3
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)
Reply
#4
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)
Reply
#5
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.
Reply
#6
(I've merged the threads. Please don't start a new thread for the same issue.)
Reply
#7
Thanks Tannishpage, your solution works, much appreciated
Reply
#8
You are welcome. Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing a Linear Search algorithm - malformed string representation Drone4four 10 931 Jan-10-2024, 08:39 AM
Last Post: gulshan212
  Search Excel File with a list of values huzzug 4 1,217 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Trying to compare string values in an if statement israelsattleen 1 541 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  Search Outlook Inbox for set of values cubangt 1 1,064 Jun-28-2023, 09:29 PM
Last Post: cubangt
  Getting rid of old string values Pedroski55 3 1,007 Oct-11-2022, 10:56 PM
Last Post: Pedroski55
  mutable values to string items? fozz 15 2,800 Aug-30-2022, 07:20 PM
Last Post: deanhystad
  Search multiple CSV files for a string or strings cubangt 7 8,006 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
  Search string in mutliple .gz files SARAOOF 10 6,926 Aug-26-2021, 01:47 PM
Last Post: SARAOOF
  fuzzywuzzy search string in text file marfer 9 4,558 Aug-03-2021, 02:41 AM
Last Post: deanhystad
  I want to search a variable for a string D90 lostbit 3 2,618 Mar-31-2021, 07:14 PM
Last Post: lostbit

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020