-6

For example My string is 'I love you' characters are 'z' 'p' 'q' 'l'

It should return true because 'I love you' contains 'l'

Rakesh SR
  • 1
  • 1

2 Answers2

3

You can convert both the strings to a set and check if there are any common chars by finding intersection

>>> set('I love you') & set('zpql')
{'l'}
>>> bool(set('I love you') & set('zpql'))
True
Aran-Fey
  • 35,525
  • 9
  • 94
  • 135
Sunitha
  • 11,422
  • 2
  • 17
  • 22
1

You can use any to do a lazy evaluation.

my_string = 'I love you' 
characters = ('z', 'p', 'q', 'l')
print(any(letter in my_string for letter in characters))

Will print True if any of the letters in characters are contained in my_string

Reblochon Masque
  • 33,202
  • 9
  • 48
  • 71