Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.060 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.01; 'else:': 0.03; 'example:': 0.03; 'way:': 0.05; 'def': 0.15; 'message-id:@web.de': 0.16; 'requirement:': 0.16; 'meant': 0.17; 'subject:list': 0.18; '>>>': 0.18; 'header:In-Reply-To:1': 0.22; 'skip:[ 10': 0.27; 'lists': 0.28; 'from:addr:web.de': 0.30; 'relation': 0.30; 'error': 0.32; 'list': 0.32; 'to:addr:python-list': 0.33; "i've": 0.34; 'header :User-Agent:1': 0.34; 'right,': 0.34; 'clarify': 0.34; 'ordered': 0.34; 'skip:" 10': 0.36; 'but': 0.37; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'chosen': 0.40; 'stated': 0.67; 'received:188': 0.68; 'care': 0.71; 'received:172.20': 0.73; 'free?': 0.84; 'received:217.72.192.234': 0.84; 'received:fmmailgate03.web.de': 0.84; 'schrieb': 0.84; 'sender:addr:web.de': 0.84 Date: Tue, 16 Aug 2011 17:26:08 +0200 From: Johannes User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20110624 Thunderbird/5.0 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> <4E4A238F.7030003@shopzeus.com> In-Reply-To: <4E4A238F.7030003@shopzeus.com> X-Enigmail-Version: 1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: dajo.mail@web.de X-Sender: dajo.mail@web.de X-Provags-ID: V01U2FsdGVkX19OL4/jYzGf0qr/P12Gi2kqCk+zeh4kOqCB95LM f9sdsFUMC8vzvx0eOrIXqI04rmlJchVpBSg/4PRwkKnjeW6+rC Xig/ftIkQ= 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313508372 news.xs4all.nl 23846 [2001:888:2000:d::a6]:35836 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11565 Am 16.08.2011 10:00, schrieb Laszlo Nagy: > >> 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] I dont care about this case, because all list are ordered for me. I've chosen the following solution > def _list_contained_in_list(l1,l2): > d1 = {} > d2 = {} > for i in l1: > if i in d1: > d1[i] += 1 > else: > d1[i] = 1 > for i in l2: > if i in d2: > d2[i] += 1 > else: > d2[i] = 1 > if not all([k in d2.keys() for k in d1.keys()]): > return false > return all([d1[i] <= d2[i] for i in d1]) greatz Johannes