Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'element': 0.07; 'problem:': 0.07; '[1,': 0.09; 'template': 0.14; 'compares': 0.16; 'depth?': 0.16; 'elem': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'nesting': 0.16; 'sorts': 0.16; 'sublist': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'appears': 0.22; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'code': 0.31; 'occurs': 0.31; 'once,': 0.31; 'lists': 0.32; 'subject:lists': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'shows': 0.36; 'so,': 0.37; 'list': 0.37; 'lists.': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'ensure': 0.60; 'guarantee': 0.63; 'more': 0.64; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=FccMrf5nLzJNPVUMvoK90nTpq3L9sVzNq0vnhVoMzpc=; b=WmKq+ruqXGSHw4jfKguM4T6OfRwCC8d4F8nE/UMLJbl6HOWgZEsX/NrKeaU2HwxF3p aO7omx/x32Q+fJoqYxj2zuZVjySYqBEFIhESSnZ051cxwW516cHBlXm+fbj2v5WzgbBM USFaVMeH1jWFo0RzUrVZxeN/aMLxLIS4zVXhpKbdAGRLgWo2I3JeuBRRi6bZ8nau1Et9 AZEWagpTYIPMqJ2/FrmAy3lEuZOyBBfFeNHxKndJ/csejjbX3Zo8ziWQek+zTUEzqDHh 8XdIIt1Eygi9TqQKVX1FcOm/uZGI9RylWawYatnpR/Tx53IAgyKHCyKfdCdhK6qgZ8Tq pvIw== MIME-Version: 1.0 X-Received: by 10.68.21.66 with SMTP id t2mr16742781pbe.151.1383939891043; Fri, 08 Nov 2013 11:44:51 -0800 (PST) In-Reply-To: References: Date: Sat, 9 Nov 2013 06:44:50 +1100 Subject: Re: Count each unique element in list of lists From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383939900 news.xs4all.nl 15883 [2001:888:2000:d::a6]:33426 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58844 On Sat, Nov 9, 2013 at 6:28 AM, Ya=C5=9Far Arabac=C4=B1 wrote: > I want to write a code that > shows that each elem in sublists of result on appears once in whole > sublist in order to add it to > my doctest. So, to clarify the problem: You want to ensure that every element occurs exactly once, neither more nor less? And you have a guarantee that the lists and sublists have a specific nesting depth? Try this: [sorted((x for l in result for x in l)) for result in results] Flattens and sorts the lists. [sorted((x for l in result for x in l))=3D=3Dlist(range(1,10)) for result in results] Flattens, sorts, and compares with a template list (which in this case is [1, 2, 3, 4, 5, 6, 7, 8, 9] from range()). ChrisA