Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32416

Re: OrderedDict / DIctComprehension

Newsgroups comp.lang.python
Date 2012-10-29 12:03 -0700
References <b8a2f8fa-c53d-413b-b3df-5883d075a012@googlegroups.com>
Message-ID <7e12e7ef-5a61-4418-bbc1-95bb92536d9b@googlegroups.com> (permalink)
Subject Re: OrderedDict / DIctComprehension
From Christian <mining.facts@googlemail.com>

Show all headers | View raw


Too bad that's not (using python2.7)
'ordered_dict_generator' ((), {}) 1.089588 sec

Anyway thanks for your hint!

> 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
> 
> 
> 
> 
> 
> @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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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