Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58844

Re: Count each unique element in list of lists

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 <rosuav@gmail.com>
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 <CAFEUn8YLenOS1F8O9-d+wZgvp9MGL-ZrQSxfR7uTi4mF5A6DSg@mail.gmail.com>
References <CAFEUn8YLenOS1F8O9-d+wZgvp9MGL-ZrQSxfR7uTi4mF5A6DSg@mail.gmail.com>
Date Sat, 9 Nov 2013 06:44:50 +1100
Subject Re: Count each unique element in list of lists
From Chris Angelico <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2244.1383939900.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Sat, Nov 9, 2013 at 6:28 AM, Yaşar Arabacı <yasar11732@gmail.com> 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))==list(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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Count each unique element in list of lists Chris Angelico <rosuav@gmail.com> - 2013-11-09 06:44 +1100

csiph-web