Python Forum
Ho to check if string contains substring from list
Thread Rating:
  • 5 Vote(s) - 3.4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ho to check if string contains substring from list
#1
i want to check if a string contains a substring from a list of string i provide, at the moment i am doing this:


                      if 'U19' in echipa1 or 'U20' in echipa1 or 'U17' in echipa1 or 'U21' in echipa1 :
                            print ("Echipele nu sunt bune")
i want to create a list and check from it:

NotOklist = ('U19','U20','U17','U21')
if echipa1 in any(NotOKlist)
    print ("Echipele nu sunt bune")  
Reply
#2
NotOKlist = ('U19','U20','U17','U21')
if any(s in echipa1 for s in NotOKlist):
    print ("Echipele nu sunt bune")
Reply
#3
Thank you
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 390 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  [solved] list content check paul18fr 6 677 Jan-04-2024, 11:32 AM
Last Post: deanhystad
  extract substring from a string before a word !! evilcode1 3 531 Nov-08-2023, 12:18 AM
Last Post: evilcode1
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,507 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  [SOLVED] [regex] Why isn't possible substring ignored? Winfried 4 1,056 Apr-08-2023, 06:36 PM
Last Post: Winfried
  ValueError: substring not found nby2001 4 7,912 Aug-08-2022, 11:16 AM
Last Post: rob101
  Match substring using regex Pavel_47 6 1,409 Jul-18-2022, 07:46 AM
Last Post: Pavel_47
  check if element is in a list in a dictionary value ambrozote 4 1,954 May-11-2022, 06:05 PM
Last Post: deanhystad
  How to check if a list is in another list finndude 4 1,831 Jan-17-2022, 05:04 PM
Last Post: bowlofred
  Substring Counting shelbyahn 4 6,112 Jan-13-2022, 10:08 AM
Last Post: krisputas

Forum Jump:

User Panel Messages

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