1

I know how to check if a string contain a particular pattern ex :

my_list=['hello.1', 'Holla',"Bonjour+","Saloute"]

for i in my_list:
 if '.1' in i:
  print(i)


hello.1

but how to add several patterns? for instance :

for i in my_list:
 if '.1' or '+' in i:
  print(i)


hello.1
Bonjour+
Ch3steR
  • 20,090
  • 4
  • 28
  • 58
Grendel
  • 783
  • 4
  • 12
  • 1
    Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – manveti Mar 23 '20 at 18:25

1 Answers1

1

You can use any here.

liste=['hello.1', 'Holla', 'Bonjour+', 'Saloute']

for word in liste:
    if any(i in word for i in ('.1','+')):
       print(word)
hello.1
Bonjour+

Or

You can write

if '.1' in word or '+' in word
Ch3steR
  • 20,090
  • 4
  • 28
  • 58