Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'example:': 0.03; 'way:': 0.05; 'not?': 0.09; 'ignores': 0.16; 'requirement:': 0.16; 'sublist': 0.16; 'meant': 0.17; 'subject:list': 0.18; 'header:In- Reply-To:1': 0.22; 'interpreted': 0.23; 'skip:[ 10': 0.27; 'lists': 0.28; 'elements': 0.29; 'not.': 0.30; 'relation': 0.30; 'error': 0.32; 'list': 0.32; 'words,': 0.32; 'does': 0.32; 'to:addr:python-list': 0.33; 'however,': 0.34; 'header:User- Agent:1': 0.34; 'right,': 0.34; 'clarify': 0.34; 'lists?': 0.34; 'post': 0.36; 'skip:" 10': 0.36; 'but': 0.37; 'two': 0.37; 'easier': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.39; 'order': 0.62; 'stated': 0.67; 'order,': 0.73; 'free?': 0.84 Date: Tue, 16 Aug 2011 10:00:15 +0200 From: Laszlo Nagy User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: testing if a list contains a sublist References: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> In-Reply-To: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313481619 news.xs4all.nl 23894 [2001:888:2000:d::a6]:54954 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11524 > Error free? Consider this stated requirement: >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 If you look it the strict way, "containment" relation for lists is meant this way: l1 = [] l2 = [1,l1,2] # l2 CONTAINS l1 But you are right, I was wrong. So let's clarify what the OP wants! For example: l1 = [1,2,2,], l2 = [2,1,2,3,4,5] What is the relation between these two lists? Does l2 contain l1 or not? In other words, is this "containment" relation interpreted on multisets not considering the order of the items? > > It also completely ignores list order, which would make [9,8,7] a > sublist of [5,6,7,8,9]. Exactly. However, from the original post of Johannes it was not clear if the order of the elements counts or not. If It this is interpreted as a multiset relation, it would be easier to use collections.Counter. If the order of elements is important then he can start with a Boyer-Moore algorithm. Best, Laszlo