-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
  • 39,665
  • 11
  • 104
  • 149
Sunitha
  • 11,777
  • 2
  • 20
  • 23
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
  • 35,405
  • 10
  • 55
  • 80