Re: Efficiently building ordered dict

2010-02-22 Thread John Posner
On 2/22/2010 4:29 PM, Bryan wrote: Sorry about the sorted != ordered mix up. I want to end up with a *sorted* dict from an unordered list. *Sorting the list is not practical in this case.* I am using python 2.5, with an ActiveState recipe for an OrderedDict. Have you looked at this: htt

Re: Efficiently building ordered dict

2010-02-22 Thread Bryan
On Feb 22, 3:00 pm, "Diez B. Roggisch" wrote: > Am 22.02.10 23:48, schrieb Bryan: > > > > > On Feb 22, 2:16 pm, "Diez B. Roggisch"  wrote: > >> Am 22.02.10 22:29, schrieb Bryan: > > >>> On Feb 22, 10:57 am, "Alf P. Steinbach"    wrote: > * Bryan: > > > I am looping through a list and crea

Re: Efficiently building ordered dict

2010-02-22 Thread MRAB
Bryan wrote: On Feb 22, 2:16 pm, "Diez B. Roggisch" wrote: Am 22.02.10 22:29, schrieb Bryan: On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: * Bryan: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build

Re: Efficiently building ordered dict

2010-02-22 Thread Diez B. Roggisch
Am 22.02.10 23:48, schrieb Bryan: On Feb 22, 2:16 pm, "Diez B. Roggisch" wrote: Am 22.02.10 22:29, schrieb Bryan: On Feb 22, 10:57 am, "Alf P. Steinbach"wrote: * Bryan: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't

Re: Efficiently building ordered dict

2010-02-22 Thread Bryan
On Feb 22, 2:16 pm, "Diez B. Roggisch" wrote: > Am 22.02.10 22:29, schrieb Bryan: > > > > > On Feb 22, 10:57 am, "Alf P. Steinbach"  wrote: > >> * Bryan: > > >>> I am looping through a list and creating a regular dictionary.  From > >>> that dict, I create an ordered dict.  I can't think of a way

Re: Efficiently building ordered dict

2010-02-22 Thread Diez B. Roggisch
Am 22.02.10 22:29, schrieb Bryan: On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: * Bryan: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build the ordered dict while going through the original loop. Is th

Re: Efficiently building ordered dict

2010-02-22 Thread Arnaud Delobelle
On 22 Feb, 21:29, Bryan wrote: > Sorry about the sorted != ordered mix up.  I want to end up with a > *sorted* dict from an unordered list.  *Sorting the list is not > practical in this case.*  I am using python 2.5, with an ActiveState > recipe for an OrderedDict. Why does the dict need to be so

Re: Efficiently building ordered dict

2010-02-22 Thread Bryan
On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: > * Bryan: > > > > > I am looping through a list and creating a regular dictionary.  From > > that dict, I create an ordered dict.  I can't think of a way to build > > the ordered dict while going through the original loop.  Is there a > > way I can a

Re: Efficiently building ordered dict

2010-02-22 Thread Alf P. Steinbach
* Bryan: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build the ordered dict while going through the original loop. Is there a way I can avoid creating the first unordered dict just to get the ordered dict?

Re: Efficiently building ordered dict

2010-02-22 Thread Mark Lawrence
Bryan wrote: On Feb 22, 9:19 am, MRAB wrote: Bryan wrote: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build the ordered dict while going through the original loop. Is there a way I can avoid creating the

Re: Efficiently building ordered dict

2010-02-22 Thread Arnaud Delobelle
Bryan writes: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the >

Re: Efficiently building ordered dict

2010-02-22 Thread MRAB
Bryan wrote: On Feb 22, 9:19 am, MRAB wrote: Bryan wrote: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build the ordered dict while going through the original loop. Is there a way I can avoid creating the

Re: Efficiently building ordered dict

2010-02-22 Thread Bryan
On Feb 22, 9:19 am, MRAB wrote: > Bryan wrote: > > I am looping through a list and creating a regular dictionary.  From > > that dict, I create an ordered dict.  I can't think of a way to build > > the ordered dict while going through the original loop.  Is there a > > way I can avoid creating the

Re: Efficiently building ordered dict

2010-02-22 Thread MRAB
Bryan wrote: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build the ordered dict while going through the original loop. Is there a way I can avoid creating the first unordered dict just to get the ordered dic

Re: Efficiently building ordered dict

2010-02-22 Thread Daniel Stutzbach
On Mon, Feb 22, 2010 at 10:32 AM, Bryan wrote: > unorderedDict = {} > for thing in unorderedList: >if thing.id in unorderedDict: >UpdateExistingValue(unorderedDict[thing.id]) >else: >CreateNewValue(unorderedDict[thing.id]) > > orderedDict = OrderedD

Re: Efficiently building ordered dict

2010-02-22 Thread Shashwat Anand
OrderedDict is a class in collection module in python 2.7a3+. Perhaps you can use it from there. >>> dir(collections) ['Callable', 'Container', 'Counter', 'Hashable', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'Mapping', 'MappingView', 'MutableMapping', 'MutableSequence', 'MutableSet', 'Orde

Efficiently building ordered dict

2010-02-22 Thread Bryan
I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build the ordered dict while going through the original loop. Is there a way I can avoid creating the first unordered dict just to get the ordered dict? Also, I am