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: 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: References: Date: Fri, 20 May 2011 21:57:44 +1000 Subject: Re: Python sets which support multiple same elements From: Chris Angelico 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Fri, May 20, 2011 at 9:37 PM, ErichCart ErichCart 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): > =A0w2=3Dlist(w2) > =A0for c in w1: > =A0 =A0if c not in w2: > =A0 =A0 =A0return False > =A0 =A0else: > =A0 =A0 =A0w2.remove(c) > =A0return 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