Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!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.031 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'skip:[ 20': 0.03; 'false.': 0.07; 'subject:test': 0.07; 'moreover,': 0.09; 'lambda': 0.16; 'message-id:@web125505.mail.ne1.yahoo.com': 0.16; 'subject:expression': 0.16; 'sublist': 0.16; 'element': 0.17; 'integer': 0.17; 'to:name:python-list@python.org': 0.20; 'to:2**1': 0.23; 'header:In-Reply-To:1': 0.25; 'skip:[ 10': 0.26; "doesn't": 0.28; 'correct': 0.28; 'prints': 0.29; 'strings,': 0.29; 'url:mailman': 0.29; 'checks': 0.30; 'lists': 0.31; 'url:python': 0.32; '-----': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'reply-to:addr:yahoo.com': 0.34; 'list': 0.35; 'false': 0.35; 'expected': 0.35; 'subject:': 0.36; 'but': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.36; 'test': 0.36; 'sent:': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'help': 0.40; 'url:mail': 0.40; 'email name:python-list': 0.62; 'results': 0.65; 'header:Reply-To:1': 0.68; '2013': 0.84; '7:25': 0.84; 'why?': 0.84; 'received:98.138.226': 0.91 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 109310.55011.bm@omp1030.mail.ne1.yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1357415997; bh=MQ97N++BZFTR1a9O+dB2Usv/QhkcqudNtopAWFPUC6Q=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ALh+b6cmfyALY41wnbwHWMTKtOP+DDLhvLztpRPeAcYX1KL1ckTD6gatANHA4LhUtGwSAcPz2kZEbVvd4kF/oFAqTa5J6Mtd9ymm52CGc3Np/baaC5OeY4uL3cCz1cP5StlYmFKnHltFutSdXCOhfzfmJdO5saPveUdHisWbsdA= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=22zOoJW/Q8+FbM1nxN2fBbTcX/grPhN7eMGTXUQABtkP1mxeoS0nRW52DEsTLlq9/NaqZ2iAth2e6qiM3no//wBYesiVZOjvgyzpCGbaHldnmRlFo+01rtq2gNUJmjdvvbCiQuFj+QPGax2YaS7CwFpdIXTKCmJX1g6a9J4mn/Q=; X-YMail-OSG: th8JNzwVM1kGvKQKWOSuP.6bnycMYMJ7wgo4cNsQZsuZMVT G39shXd66q4DqsqeuFkeSbMgDaPhDSOFszMAwxZnvacnebSwqYP0zqscfiM5 eDPzQwf9UNEwzekG_1SIs7yZjgGbHnVzuSbNfKWzxacs5Gfdm8ztTudGno.. KbVKfIOEHsBlU4Jph2llQCeRRXEe79a.ZT3m8VR7pbx_c63gCiAzOCUVzndO YLUNtVNyIYlmCVwdQd8uGynMJ.GNKbGw48LPQW0o1ldzUGoo_6sDjbSkAO8O pibn4.T.tA1rLK.XkU2Q4XYtIz_.ePPrac08mSfvl3Nv6TiZhsxcbCy8AX8t 4.eu.S1R1yX5Ee87ad.tkEEiO1l76RZhV5veoEMw.YCTYhEBiEkLi0Yf8LHL nusk_5uLpulG7m_gbpgBfiUbshtl1xBsEgluK77LxlYZZ7weD_yLmrCVZgXV MmFrkSlATlpcNTIQRViPvhX0vhp56.yeo37FB19IJ0qSus4DgOhmBnQIYGfH kCfyJKhDDWerPGuQfcqkmgpB4pnY5gI4rZvdfvY8- X-Rocket-MIMEInfo: 001.001, QmVjYXVzZSByZWR1Y2UgZG9lc24ndCBkbyB3aGF0IHlvdSB3YW50LiBZb3UnZCB3YW50ICJhbGwiLgoKTDEgPSBbMSwyLDNdCkwyID0gWyJBMSIsIkIyIiwiQzMiLDEsMiwzXQpwcmludCBhbGwoKHggaW4gTDIgZm9yIHggaW4gTDEpKSAjIHByaW50cyBUcnVlCkwzID0gWyJBMSIsIkIyIiwiQzMiXQpwcmludCBhbGwoKHggaW4gTDIgZm9yIHggaW4gTDMpKSAjIHByaW50cyBUcnVlCgoKCgotLS0tLSBPcmlnaW5hbCBNZXNzYWdlIC0tLS0tCkZyb206IEFzaW0gPGFzaW0uci5wQGdtYWlsLmNvbT4KVG86IHB5dGgBMAEBAQE- X-Mailer: YahooMailWebService/0.8.129.483 References: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> Date: Sat, 5 Jan 2013 11:59:56 -0800 (PST) From: chaouche yacine Subject: Re: reduce expression to test sublist To: Asim , "python-list@python.org" In-Reply-To: <76cd3945-392e-40d4-9f87-d3956b9521d2@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: chaouche yacine 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357416164 news.xs4all.nl 6875 [2001:888:2000:d::a6]:47893 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36204 Because reduce doesn't do what you want. You'd want "all".=0A=0AL1 =3D [1,2= ,3]=0AL2 =3D ["A1","B2","C3",1,2,3]=0Aprint all((x in L2 for x in L1)) # pr= ints True=0AL3 =3D ["A1","B2","C3"]=0Aprint all((x in L2 for x in L3)) # pr= ints True=0A=0A=0A=0A=0A----- Original Message -----=0AFrom: Asim =0ATo: python-list@python.org=0ACc: =0ASent: Saturday, January 5= , 2013 7:25 PM=0ASubject: reduce expression to test sublist=0A=0AHi All=0A= =0AThe following reduce expression checks if every element of list lst1 is = present in list lst2.=A0 It works as expected for integer lists but for lis= ts of strings, it always returns False.=0A=0A=A0 reduce( lambda x,y: (x in= lst2) and (y in lst2), lst1)=0A=0AMoreover, for the lists of strings the f= ollowing for-loop gives correct results when the above reduce expression do= esn't.=0A=0A=A0 isSublist =3D True=0A=A0 for i in lst1:=0A=A0 =A0 =A0 isS= ublist =3D isSublist and (i in lst2)=0A=A0 =A0 =A0 if not isSublist:=0A=A0 = =A0 =A0 =A0 isSublist =3D False=0A=A0 =A0 =A0 =A0 break=0A=0A=0ACan someo= ne help me understand why?=0A=0AAsim=0A-- =0Ahttp://mail.python.org/mailman= /listinfo/python-list=0A