0
How do I check if elements in string are in another string and the index position in the other string g in python?
5 Respostas
+ 2
>>> a = 'abc'
>>> b = 'weabczq'
>>> a in b #check if b contains a
True
>>> b.find(a) #index position
2
0
it depends on what you are meaning by "elements of string are in another string". unique or multiple? in same order or not? please clarify or make an example.
0
unique, not in the same order
0
strA = 'abcdef'
strB = 'abddc'
strC = 'adbcg'
def checkString (s1, s2):
for char in s1:
if char not in s2:
return False
return True
print (checkString(strB, strA)) #prints True
print (checkString(strC, strA)) #prints False
0
thanks