Python Forum
How to iterate through a list and search for a value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to iterate through a list and search for a value
#1
Hi everyone,
First time poster here. Been studying python about 2 weeks now.

I am trying to loop through a list to check if a certain value is in it. The value will be random but will always contain a * at the front.

Here is the code I am using to loop through:
for x in stringsplit:
    if x = \*:
    print (x)
I am getting this error from python: SyntaxError: invalid syntax
And pycharm tells me there is a : expected in the if statement even though it already has one.

I feel like in other languages I would use a contains function but this does not exist in python.

I have spent around 3-4 hours searching the web and I have come back with nothing.

Help appreciated.
Reply


Messages In This Thread
How to iterate through a list and search for a value - by fad3r - Jan-23-2018, 12:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Excel File with a list of values huzzug 4 1,266 Nov-03-2023, 05:35 PM
Last Post: huzzug
  search a list or tuple for a specific type ot class Skaperen 8 1,953 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  Use one list as search key for another list with sublist of list jc4d 4 2,174 Jan-11-2022, 12:10 PM
Last Post: jc4d
  Search in an unsorted list amir_0402 2 15,301 Jun-04-2020, 10:25 PM
Last Post: deanhystad
  Alpha numeric element list search rhubarbpieguy 1 1,797 Apr-01-2020, 12:41 PM
Last Post: pyzyx3qwerty
  search binary file and list all founded keyword offset Pyguys 4 2,789 Mar-17-2020, 06:46 AM
Last Post: Pyguys
  Trying to iterate through a list... t4keheart 2 1,681 Feb-07-2020, 08:15 PM
Last Post: t4keheart
  Using Python to search through a list of urls jeremy 4 2,879 Dec-18-2019, 11:52 AM
Last Post: Malt
  list of lists iterate only sends the last value batchenr 1 1,904 Sep-24-2019, 07:04 AM
Last Post: Gribouillis
  Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV dn237 19 6,746 May-29-2019, 02:27 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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