Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5853
| References | <f7760e6f-b176-4c13-8285-08d7689ece02@f31g2000pri.googlegroups.com> |
|---|---|
| Date | 2011-05-20 21:57 +1000 |
| Subject | Re: Python sets which support multiple same elements |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1839.1305892667.9059.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Find similar | Unroll 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