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


Groups > comp.lang.python > #32365

OrderedDict / DIctComprehension

Newsgroups comp.lang.python
Date 2012-10-29 05:36 -0700
Message-ID <b8a2f8fa-c53d-413b-b3df-5883d075a012@googlegroups.com> (permalink)
Subject OrderedDict / DIctComprehension
From Christian <mining.facts@googlemail.com>

Show all headers | View raw


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