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


Groups > comp.lang.python > #5853

Re: Python sets which support multiple same elements

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!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.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'pm,': 0.10; 'this:': 0.10; 'def': 0.12; 'wrote:': 0.14; 'angelico': 0.16; 'equal.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; '\xa0for': 0.16; 'header:In- Reply-To:1': 0.21; 'detect': 0.22; 'received:209.85.210.174': 0.23; 'received:mail-iy0-f174.google.com': 0.23; '\xa0if': 0.23; 'fri,': 0.23; 'versions': 0.23; 'message-id:@mail.gmail.com': 0.28; 'helpful': 0.28; 'subject:same': 0.30; 'subject:support': 0.30; 'sort': 0.31; 'to:addr:python-list': 0.33; 'chris': 0.34; 'example,': 0.35; 'lists,': 0.36; '8bit%:8': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; '20,': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'simply': 0.60; 'other.': 0.63
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=4Y9cHzkFFEk70xkInGJoNHbw7m5OmI+Five+LAHEoho=; b=k5hl8Dt8Y6yxKqJcbmZVgUI7gj8U2YevtuWqVVVYovZXtdSb97Fl0wtUMOElnbtOtk sajLnUKRnpONHw2yxAgOV3xhhmJhyUcjREqxFHK/ZhKUonxXBkNfl7NOaqLa3+dkzHyx zLSULF6jsoPHSZe0bze0k8rcozWd3qbDYD2rc=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=bKGsXfRWArOkE8ZCpil2jqUdj+14Ouzonev7C4rS/oZSUiuBX/QDsklFWiezx6mpUq S4NRUMijezaeKMUHr3EwbcJvpPsPlOKosfioCj8sWMyLvvg7DFrvcUxVQqVMIL5BqOq9 FbqReAmRlJYhP0clO2Opxvn0uYpPpZoBaFIP4=
MIME-Version 1.0
In-Reply-To <f7760e6f-b176-4c13-8285-08d7689ece02@f31g2000pri.googlegroups.com>
References <f7760e6f-b176-4c13-8285-08d7689ece02@f31g2000pri.googlegroups.com>
Date Fri, 20 May 2011 21:57:44 +1000
Subject Re: Python sets which support multiple same elements
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
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.1839.1305892667.9059.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 82.94.164.166
X-Trace 1305892668 news.xs4all.nl 49177 [::ffff:82.94.164.166]:34780
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5853

Show key headers only | View raw


On Fri, May 20, 2011 at 9:37 PM, ErichCart ErichCart
<erichcart@gmail.com> wrote:
> For example, I was writing a program to detect whether two strings are
> anagrams of each other. I had to write it like this:
>
> def isAnagram(w1, w2):
>  w2=list(w2)
>  for c in w1:
>    if c not in w2:
>      return False
>    else:
>      w2.remove(c)
>  return True

You may find it helpful to simply sort the lists, keeping them as
lists. If they're anagrams of each other, their sorted versions will
be equal.

Chris Angelico

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


Thread

Python sets which support multiple same elements ErichCart ErichCart <erichcart@gmail.com> - 2011-05-20 04:37 -0700
  RE: Python sets which support multiple same elements Andreas Tawn <andreas.tawn@ubisoft.com> - 2011-05-20 13:53 +0200
  Re: Python sets which support multiple same elements Chris Angelico <rosuav@gmail.com> - 2011-05-20 21:57 +1000

csiph-web