0

I'm trying to determine if any characters from a string1 are in another string2

example:
string1 = "abcdefghijklmnopqrstuvwxyz"

any of the characters from this string1 are in this string2 for example:

string2="HELLO WoRLD"

but i want to do so without using any loops, is there anything that can be done in python maybe using the in statement

Beni
  • 51
  • 7

1 Answers1

2

You can do it using sets

str1 = 'abcd'
str2 = 'bcde'

set1 = set(str1) 
set2 = set(str2)

if set1.intersection(set2):
    print('There are same chars in the strings')
bottledmind
  • 603
  • 3
  • 10