Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4074
| 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 | <prahamark@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.093 |
| X-Spam-Evidence | '*H*': 0.82; '*S*': 0.00; 'operator': 0.05; 'python': 0.07; '3.2.': 0.16; 'caveat': 0.16; 'comparisons,': 0.16; 'cc:no real name:2**0': 0.20; 'subject:list': 0.22; 'header:In-Reply- To:1': 0.22; 'cc:addr:python-list': 0.22; 'received:209.85.213': 0.23; 'list': 0.30; 'cc:addr:python.org': 0.31; 'cc:addr:gmail.com': 0.31; 'tuples': 0.31; 'import': 0.32; 'initial': 0.32; 'header:User-Agent:1': 0.35; 'items.': 0.35; 'some': 0.37; 'received:209.85': 0.37; 'time:': 0.38; 'received:google.com': 0.38; 'cc:2**1': 0.38; 'under': 0.39; 'received:209': 0.39; '(3)': 0.64; '(4)': 0.65; 'to:addr:googlegroups.com': 0.69; 'reply-to:no real name:2**0': 0.72; 'header:Reply-To:1': 0.72; '(5)': 0.77; 'reply- to:addr:googlegroups.com': 0.93 |
| Newsgroups | comp.lang.python |
| Date | Tue, 26 Apr 2011 12:39:32 -0700 (PDT) |
| In-Reply-To | <mailman.856.1303842605.9059.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=207.229.149.157; posting-account=yjzYUgoAAAB_PKEzWUqDhDdSzxKMCeMa |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Subject | Re: De-tupleizing a list |
| From | Mark Niemczyk <prahamark@gmail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list@python.org, Gnarlodious <gnarlodious@gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | comp.lang.python@googlegroups.com |
| 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> |
| Message-ID | <mailman.868.1303847500.9059.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1303847501 news.xs4all.nl 81482 [::ffff:82.94.164.166]:40502 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4074 |
Show key headers only | View raw
Some interesting performance comparisons, under Python 3.2. Times are relative, and are for an initial list of tuples with 500,000 items.
(1) ans = [] #relative time: 298
for item in lst:
ans += list(item)
return ans
(2) return [item[0] for item in lst] #relative time: 106
(3) from operator import itemgetter #relative time: 84
return list(map(itemgetter(0), lst))
(4) import itertools #relative time: 63
return list(itertools.chain.from_iterable(lst))
(5) return [x for (x,) in lst] #relative time: 52
With the caveat that 'your mileage may vary'
Regards,
Mark
Back to comp.lang.python | Previous | Next | Find similar
Re: De-tupleizing a list Mark Niemczyk <prahamark@gmail.com> - 2011-04-26 12:39 -0700
csiph-web