testing if a list contains a sublist

Nobody nobody at nowhere.com
Tue Aug 16 07:21:47 EDT 2011

On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote:

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

"Best" is subjective. AFAIK, the theoretically-optimal algorithm is
Boyer-Moore. But that would require a fair amount of code, and Python
isn't a particularly fast language, so you're likely to get better results
if you can delegate most of the leg-work to a native library (along the
lines of Roy's suggestion of using regexps).

More information about the Python-list mailing list