Labels

new blog 2.0

2011/12/12

Python issublist()

An inefficient yet basic and mostly sufficient implementation of a Python function asserting that elements of one iterator are a sublist another's.

def issublist(a, b):
    sep = '\xC0\xFF\xEE'
    a_str = '%s%s%s' % (sep, sep.join(['%s' % e for e in a]), sep)
    b_str = '%s%s%s' % (sep, sep.join(['%s' % e for e in b]), sep)
    return a_str in b_str

No comments: