Here is what you can do:
def isSubsequence(s, t):
s = list(s)
for i,(a,b) in enumerate(zip(t,s)):
if a != b:
s.insert(i,'.')
return len(t) == len(s)
print(isSubsequence('Apes are goo.', 'Apples are good.'))
Output:
True
Your case is that that specific s is not a subsequence of that specific t. To prove it:
def isSubsequence(s, t):
s = list(s)
for i,(a,b) in enumerate(zip(t,s)):
if a != b:
s.insert(i,'.')
print(t)
print(''.join(s))
s = "rjufvjafbxnbgriwgokdgqdqewn"
t = "mjmqqjrmzkvhxlyruonekhhofpzzslupzojfuoztvzmmqvmlhgqxehojfowtrinbatjujaxekbcydldglkbxsqbbnrkhfdnpfbuaktupfftiljwpgglkjqunvithzlzpgikixqeuimmtbiskemplcvljqgvlzvnqxgedxqnznddkiujwhdefziydtquoudzxstpjjitmiimbjfgfjikkjycwgnpdxpeppsturjwkgnifinccvqzwlbmgpdaodzptyrjjkbqmgdrftfbwgimsmjpknuqtijrsnwvtytqqvookinzmkkkrkgwafohflvuedssukjgipgmypakhlckvizmqvycvbxhlljzejcaijqnfgobuhuiahtmxfzoplmmjfxtggwwxliplntkfuxjcnzcqsaagahbbneugiocexcfpszzomumfqpaiydssmihdoewahoswhlnpctjmkyufsvjlrflfiktndubnymenlmpyrhjxfdcq"
isSubsequence(s, t)
Output:
mjmqqjrmzkvhxlyruonekhhofpzzslupzojfuoztvzmmqvmlhgqxehojfowtrinbatjujaxekbcydldglkbxsqbbnrkhfdnpfbuaktupfftiljwpgglkjqunvithzlzpgikixqeuimmtbiskemplcvljqgvlzvnqxgedxqnznddkiujwhdefziydtquoudzxstpjjitmiimbjfgfjikkjycwgnpdxpeppsturjwkgnifinccvqzwlbmgpdaodzptyrjjkbqmgdrftfbwgimsmjpknuqtijrsnwvtytqqvookinzmkkkrkgwafohflvuedssukjgipgmypakhlckvizmqvycvbxhlljzejcaijqnfgobuhuiahtmxfzoplmmjfxtggwwxliplntkfuxjcnzcqsaagahbbneugiocexcfpszzomumfqpaiydssmihdoewahoswhlnpctjmkyufsvjlrflfiktndubnymenlmpyrhjxfdcq
......r...........................j.u...................f...............................................................v..............................j..................................................................................................a................f..b..............................................................................x............n...b....................g....................................................................................r...i.......................wgokdgqdqewn
UPDATED to include simpler implementation given by @StevenRumbalski at the comments:
def isSubsequence(s, t, start=-1):
return all((start:=t.find(c, start+1)) > -1 for c in s)
sis also intin any order -- here's a simple example:isSubsequence('ab', 'acb')=>True. There are easier ways of testing sequence membership in Python but since it's an exercise I'm not going to just tell you ;-)s.pop(0)?!isSubsequence('ab', 'bb'). Your code currently returnsTruefor that, which is obviously not the desired result...False, since'ab'is clearly not a subsequence of'bb'.