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


Groups > comp.lang.python > #11920

Re: Compare tuples of different lenght

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <johnmohagan@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.194
X-Spam-Level *
X-Spam-Evidence '*H*': 0.63; '*S*': 0.02; 'skip:[ 40': 0.07; 'def': 0.15; 'wrote:': 0.16; 'header:In-Reply-To:1': 0.22; '-0700': 0.23; 'smallest': 0.23; 'aug': 0.24; 'sender:addr:gmail.com': 0.25; 'compare': 0.28; 'sat,': 0.28; 'work:': 0.29; 'tuples': 0.30; 'list': 0.32; 'hi,': 0.32; 'break': 0.32; 'to:addr:python-list': 0.33; 'list.': 0.35; 'charset:us-ascii': 0.36; 'element': 0.37; 'two': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'header:Message-Id:1': 0.61; 'john': 0.62; '(pdt)': 0.84; 'subject:different': 0.84; 'received:209.85.218.46': 0.91; 'received:home': 0.91; 'received :mail-yi0-f46.google.com': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:date:from:to:subject:message-id:in-reply-to:references :x-mailer:mime-version:content-type:content-transfer-encoding; bh=YqAi6gFI3KGm7W8I6QjvITlohr+/f/JxJ+qmIq+5cc4=; b=WeaP3h5Vvn+E9XCy+gzYIf4IloIIk6QS+ZyWMP518U2J0S2gGaENruHoZiCIICIxuW hubuig6Evz5nbxcklCYr1QgHfcnFthA8vmY1WXlKM50BYsGf2pR0t1kdyCy5pbxOtyqL Cx1LFGejFmnFldMxrdRkywq0mV5sgMRhUT3ms=
Sender "John O'Hagan" <johnmohagan@gmail.com>
Date Sun, 21 Aug 2011 01:03:05 +1000
From John O'Hagan <research@johnohagan.com>
To python-list@python.org
Subject Re: Compare tuples of different lenght
In-Reply-To <c5deea4a-7e0a-491f-8425-ab1c2acf6c60@t9g2000vbs.googlegroups.com>
References <c5deea4a-7e0a-491f-8425-ab1c2acf6c60@t9g2000vbs.googlegroups.com>
X-Mailer Sylpheed 3.2.0beta1 (GTK+ 2.24.4; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
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 <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.266.1313852603.27778.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313852603 news.xs4all.nl 23931 [2001:888:2000:d::a6]:33247
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11920

Show key headers only | View raw


On Sat, 20 Aug 2011 01:25:18 -0700 (PDT)
Jurgens de Bruin <debruinjj@gmail.com> wrote:

> Hi,
> 
> I have a list of tuples:
> 
> [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),]
> 
> I would like to compare all the tuples to each other and if one
> element if found two tuples the smallest tuples is removed from the
> list.
[...]

This should work:

def long_match(tuples):
    sorted_tuples = sorted(tuples, key=len)
    for n, t in enumerate(sorted_tuples):
        for s in sorted_tuples[n + 1:]:
            if len(s) > len(t) and any(i in s for i in t):    
                tuples.remove(t)
                break
    return tuples 
 

Regards,

John

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


Thread

Compare tuples of different lenght Jurgens de Bruin <debruinjj@gmail.com> - 2011-08-20 01:25 -0700
  Re: Compare tuples of different lenght Chris Rebert <clp2@rebertia.com> - 2011-08-20 01:45 -0700
    Re: Compare tuples of different lenght Jurgens de Bruin <debruinjj@gmail.com> - 2011-08-20 01:54 -0700
    Re: Compare tuples of different lenght Jurgens de Bruin <debruinjj@gmail.com> - 2011-08-20 02:00 -0700
  Re: Compare tuples of different lenght Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-20 20:17 +1000
    Re: Compare tuples of different lenght Jurgens de Bruin <debruinjj@gmail.com> - 2011-08-20 03:47 -0700
  Re: Compare tuples of different lenght Peter Otten <__peter__@web.de> - 2011-08-20 13:56 +0200
  Re: Compare tuples of different lenght John O'Hagan <research@johnohagan.com> - 2011-08-21 01:03 +1000

csiph-web