Roy Smith <r...@panix.com> writes:

>> what is the best way to check if a given list (lets call it l1) is
>> totally contained in a second list (l2)?

[...]
> import re
>
> def sublist(l1, l2):
>     s1 = ''.join(map(str, l1))
>     s2 = ''.join(map(str, l2))
>     return re.search(s1, s2)

This is complete nonsense (try it on [12] and [1,2]).

The original problem is "string searching" (where strings here are
sequences of numbers instead of characters). See

http://en.wikipedia.org/wiki/String_searching_algorithm

for any algorithm (Rabin-Karp seems appropriate to me).

-- Alain.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to