Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7520
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!postnews.google.com!gh5g2000vbb.googlegroups.com!not-for-mail |
|---|---|
| From | Zachary Dziura <zcdziura@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: What is the most efficient way to compare similar contents in two lists? |
| Date | Mon, 13 Jun 2011 08:21:29 -0700 (PDT) |
| Organization | http://groups.google.com |
| Lines | 21 |
| Message-ID | <bad3a56e-efba-4ef4-a159-64273cda5a08@gh5g2000vbb.googlegroups.com> (permalink) |
| References | <3ff2f4cc-7c26-4f59-9463-d6f0874174d8@dn9g2000vbb.googlegroups.com> <mailman.169.1307977750.11593.python-list@python.org> |
| NNTP-Posting-Host | 192.223.243.5 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | posting.google.com 1307978489 12053 127.0.0.1 (13 Jun 2011 15:21:29 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Mon, 13 Jun 2011 15:21:29 +0000 (UTC) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | gh5g2000vbb.googlegroups.com; posting-host=192.223.243.5; posting-account=W6anpAoAAABCcU4OKFSlcJpyVgvwTcuB |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-Header-Order | HUALSRCENK |
| X-HTTP-UserAgent | Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1,gzip(gfe) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:7520 |
Show key headers only | View raw
On Jun 13, 11:09 am, Chris Angelico <ros...@gmail.com> wrote: > On Tue, Jun 14, 2011 at 12:58 AM, Zachary Dziura <zcdzi...@gmail.com> wrote: > > if set(source_headers) == set(target_headers): > > similar_headers = len(source_headers) > > Since you're making sets already, I'd recommend using set operations - > same_headers is the (length of the) intersection of those two sets, > and different_headers is the XOR. > > # If you need the lists afterwards, use different variable names > source_headers = set(source_headers) > target_headers = set(target_headers) > similar_headers = len(source_headers & target_headers) > different_headers = len(source_headers ^ target_headers) > > Chris Angelico Wow! That was a lot easier than I thought it would be! I guess I should have done a little bit more research into such operations. Thanks a bunch!!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is the most efficient way to compare similar contents in two lists? Zachary Dziura <zcdziura@gmail.com> - 2011-06-13 07:58 -0700
Re: What is the most efficient way to compare similar contents in two lists? Chris Angelico <rosuav@gmail.com> - 2011-06-14 01:09 +1000
Re: What is the most efficient way to compare similar contents in two lists? Zachary Dziura <zcdziura@gmail.com> - 2011-06-13 08:21 -0700
Re: What is the most efficient way to compare similar contents in two lists? Chris Angelico <rosuav@gmail.com> - 2011-06-14 01:39 +1000
Re: What is the most efficient way to compare similar contents in two lists? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-13 16:04 +0000
Re: What is the most efficient way to compare similar contents in two lists? Chris Angelico <rosuav@gmail.com> - 2011-06-14 02:30 +1000
Re: What is the most efficient way to compare similar contents in two lists? geremy condra <debatem1@gmail.com> - 2011-06-13 10:46 -0700
Re: What is the most efficient way to compare similar contents in two lists? Chris Angelico <rosuav@gmail.com> - 2011-06-14 03:50 +1000
Re: What is the most efficient way to compare similar contents in two lists? geremy condra <debatem1@gmail.com> - 2011-06-13 11:20 -0700
Re: What is the most efficient way to compare similar contents in two lists? Chris Angelico <rosuav@gmail.com> - 2011-06-14 04:24 +1000
Re: What is the most efficient way to compare similar contents in two lists? Ethan Furman <ethan@stoneleaf.us> - 2011-06-13 12:11 -0700
Re: What is the most efficient way to compare similar contents in two lists? Zachary Dziura <zcdziura@gmail.com> - 2011-06-13 12:21 -0700
Re: What is the most efficient way to compare similar contents in two lists? Chris Angelico <rosuav@gmail.com> - 2011-06-14 07:33 +1000
Re: What is the most efficient way to compare similar contents in two lists? Chris Angelico <rosuav@gmail.com> - 2011-06-14 04:11 +1000
Re: What is the most efficient way to compare similar contents in two lists? Chris Torek <nospam@torek.net> - 2011-06-13 18:40 +0000
Re: What is the most efficient way to compare similar contents in two lists? Chris Angelico <rosuav@gmail.com> - 2011-06-14 04:12 +1000
csiph-web