From: Chris Rebert on
On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh <navkirats(a)gmail.com> wrote:
> Sorry, I might have been a bit vague:
> (Also, I am new to pythong)
> I am trying to do construct my own web session tracking algorithm for a web
> server (which also I have constructed). The book keeping is for the session
> information I track. The dictionary object will do this for me. I was
> initially using a plain dictionary object, but I read this in the
> documentation that made me think about the question I asked :-

Does your program actually make use of the ordering? If so, then yes,
using OrderedDict is obviously preferable (Why reimplement something
needlessly?). If not, then why bother with the extra complication?

(You are aware that the "ordered" in OrderedDict means that its keys
are ordered, and not that, say, a list containing OrderedDicts can be
sorted, right?)

Cheers,
Chris
--
http://blog.rebertia.com
From: Navkirat Singh on

On 29-Jul-2010, at 11:41 AM, Chris Rebert wrote:

> On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh <navkirats(a)gmail.com> wrote:
>> Sorry, I might have been a bit vague:
>> (Also, I am new to pythong)
>> I am trying to do construct my own web session tracking algorithm for a web
>> server (which also I have constructed). The book keeping is for the session
>> information I track. The dictionary object will do this for me. I was
>> initially using a plain dictionary object, but I read this in the
>> documentation that made me think about the question I asked :-
>
> Does your program actually make use of the ordering? If so, then yes,
> using OrderedDict is obviously preferable (Why reimplement something
> needlessly?). If not, then why bother with the extra complication?
>
> (You are aware that the "ordered" in OrderedDict means that its keys
> are ordered, and not that, say, a list containing OrderedDicts can be
> sorted, right?)
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com


I am still in the analysis phase/experimental phase and the need might arise. Hence, I just wanted to know my options. If a collections object will improve performance than an ordinary dictionary, then yes I would like to go with the OrderedDict.

Thanks,
Nav
From: Raymond Hettinger on
On Jul 28, 6:47 pm, Navkirat Singh <navkir...(a)gmail.com> wrote:
> I was wondering what would be better to do some medium
> to heavy book keeping in memory - Ordered Dictionary
> or a plain simple Dictionary object??

The current implementation of OrderedDict is based on regular
dictionaries, so it performance cannot be better than a regular
dictionary for the usual mapping operations. Some accessor methods
like __getitem__(), __len__(), __contains__(), and get() are pass
throughs, so their performance is the same. Most of the rest of the
methods are order aware and are slower by a constant factor.

So, if you don't need the ordering feature, then you're better-off
with a regular dictionary.

A potential future implementation for OrderedDict written in C would
have nearly identical performance as regular dicts for most operations
and slightly improved performance for iteration.

Raymond
From: Hrvoje Niksic on
sturlamolden <sturlamolden(a)yahoo.no> writes:

> On 29 Jul, 03:47, Navkirat Singh <navkir...(a)gmail.com> wrote:
>
>> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object??
>
> It depends on the problem. A dictionary is a hash table. An ordered
> dictionary is a binary search tree (BST).

The ordered dictionary shipped with Python is also a hash table, with an
internal list to keep track of item order.

The one thing not mentioned in the thread is that ordered dict's
deletion is O(n), which might impact "heavy bookkeeping". As Raymond
said, where order doesn't matter, it's best to stick with dict.
From: Navkirat Singh on

On 29-Jul-2010, at 2:50 PM, Hrvoje Niksic wrote:

> sturlamolden <sturlamolden(a)yahoo.no> writes:
>
>> On 29 Jul, 03:47, Navkirat Singh <navkir...(a)gmail.com> wrote:
>>
>>> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object??
>>
>> It depends on the problem. A dictionary is a hash table. An ordered
>> dictionary is a binary search tree (BST).
>
> The ordered dictionary shipped with Python is also a hash table, with an
> internal list to keep track of item order.
>
> The one thing not mentioned in the thread is that ordered dict's
> deletion is O(n), which might impact "heavy bookkeeping". As Raymond
> said, where order doesn't matter, it's best to stick with dict.
> --
> http://mail.python.org/mailman/listinfo/python-list

Thanks that was an excellent point : )