0

How do I check if elements in string are in another string and the index position in the other string g in python?

18th Nov 2016, 6:55 PM
__JAYMES
__JAYMES - avatar
5 Answers
+ 2
>>> a = 'abc' >>> b = 'weabczq' >>> a in b #check if b contains a True >>> b.find(a) #index position 2
19th Nov 2016, 10:34 AM
donkeyhot
donkeyhot - avatar
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.
18th Nov 2016, 7:36 PM
Demeth
Demeth - avatar
0
unique, not in the same order
18th Nov 2016, 7:40 PM
__JAYMES
__JAYMES - avatar
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
18th Nov 2016, 7:48 PM
Demeth
Demeth - avatar
0
thanks
18th Nov 2016, 8:01 PM
__JAYMES
__JAYMES - avatar