testing if a list contains a sublist

Laszlo Nagy gandalf at shopzeus.com
Tue Aug 16 11:17:08 EDT 2011


> That can be easily fixed:
>
>>>> def sublist(lst1, lst2):
> 	s1 = ','.join(map(str, lst1))
> 	s2 = ','.join(map(str, lst2))
> 	return False if s2.find(s1)==-1 else True
>
> I don't know about best, but it works for the examples given.
>
For numbers, it will always work. But what about

lst1 = [",",",,"]
lst1 = [",",",",","]





More information about the Python-list mailing list