Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32406
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; '{})': 0.09; 'advance': 0.10; 'def': 0.10; 'ordereddict': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'sec': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'header:X-Complaints- To:1': 0.28; "skip:' 10": 0.30; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'christian': 0.34; 'thanks': 0.34; 'faster': 0.35; 'there': 0.35; 'received:org': 0.36; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'subject:skip:D 10': 0.65; 'received:fios.verizon.net': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: OrderedDict / DIctComprehension |
| Date | Mon, 29 Oct 2012 13:15:57 -0400 |
| References | <b8a2f8fa-c53d-413b-b3df-5883d075a012@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-173-75-251-66.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 |
| In-Reply-To | <b8a2f8fa-c53d-413b-b3df-5883d075a012@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.3034.1351530986.27098.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351530986 news.xs4all.nl 6880 [2001:888:2000:d::a6]:36058 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32406 |
Show key headers only | View raw
On 10/29/2012 8:36 AM, Christian wrote:
> Hi,
>
> is there a way building an OrderedDict faster?
>
> Thanks in advance
> Christian
>
> @timeit
> def ordered(n=100000):
> d = OrderedDict()
> for i in xrange(n):
> d['key'+str(i)] = i
> return d
try d = OrderedDict(['key'+str(i),i for i in xrange(n)])
In Py3, just range(n). Also
d = OrderedDict(('key'+str(i)) for i in range(n))
may be faster or slower.
>
> @timeit
> def comprehension(n=100000):
> d = { 'key'+str(i):i for i in xrange(n) }
> return d
>
>
> ordered()
> comprehension()
>
> 'ordered' ((), {}) 0.724609 sec
> 'comprehension' ((), {}) 0.098318 sec
>
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
OrderedDict / DIctComprehension Christian <mining.facts@googlemail.com> - 2012-10-29 05:36 -0700 Re: OrderedDict / DIctComprehension Terry Reedy <tjreedy@udel.edu> - 2012-10-29 13:15 -0400 Re: OrderedDict / DIctComprehension Christian <mining.facts@googlemail.com> - 2012-10-29 12:03 -0700
csiph-web