我不知道是否有内置功能,但是手动操作相当简单
def exists(a, b): """checks if b exists in a as a subsequence""" pos = 0 for ch in a: if pos < len(b) and ch == b[pos]: pos += 1 return pos == len(b)>>> exists("moo", "mo")True>>> exists("moo", "oo")True>>> exists("moo", "ooo")False>>> exists("haystack", "hack")True>>> exists("haystack", "hach")False>>>


