Python Forum
How to check if value of a list is in a string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check if value of a list is in a string?
#1

str = "Apples are good for you"
list = ['apple', 'banana', 'pear']
this string contains a value from the list, 'apple'. How would I write an if statement to check if any values of a list are in a string without it being case sensitive? Tongue
Reply
#2
What have you tried?
Reply
#3
first of all don't not use python reserved words as variable names. It's asking for trouble.
mylist = ['Apples', 'banana', 'pear']
mystr = "Apples are good for you"

for word in mylist:
    if word in mystr:
        print(f'found {word} in {mystr}')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 318 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  [solved] list content check paul18fr 6 615 Jan-04-2024, 11:32 AM
Last Post: deanhystad
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,429 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  check if element is in a list in a dictionary value ambrozote 4 1,879 May-11-2022, 06:05 PM
Last Post: deanhystad
  How to check if a list is in another list finndude 4 1,793 Jan-17-2022, 05:04 PM
Last Post: bowlofred
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,455 Aug-12-2021, 04:25 PM
Last Post: palladium
  how to check if string contains ALL words from the list? zarize 6 7,043 Jul-22-2020, 07:04 PM
Last Post: zarize
  How to check if user entered string or integer or float?? prateek3 5 11,283 Dec-21-2019, 06:24 PM
Last Post: DreamingInsanity
  help needed plz, how to check if a string is almost the same? NickPlv 2 2,476 Apr-25-2019, 02:11 PM
Last Post: perfringo
  I converted string to 'list', but it doesn't look like a list! mrapple2020 3 3,202 Apr-07-2019, 02:34 PM
Last Post: mrapple2020

Forum Jump:

User Panel Messages

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