Python: find a list within members of another list(in order)

前端 未结 9 2087
栀梦
栀梦 2020-12-03 10:40

If I have this:

a=\'abcdefghij\'
b=\'de\'

Then this finds b in a:

b in a => True

Is there a way of doi

9条回答
  •  离开以前
    2020-12-03 11:35

    Use the lists' string representation and remove the square braces. :)

    def is_sublist(a, b):
        return str(a)[1:-1] in str(b)
    

    EDIT: Right, there are false positives ... e.g. is_sublist([1], [11]). Crappy answer. :)

提交回复
热议问题