Python Forum

Full Version: Ho to check if string contains substring from list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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")  
NotOKlist = ('U19','U20','U17','U21')
if any(s in echipa1 for s in NotOKlist):
    print ("Echipele nu sunt bune")
Thank you