Re: building a dict

2010-03-14 Thread Steve Holden
Andreas Waldenburger wrote: On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler vicente.so...@gmail.com wrote: By the way, I suppose I am the OP. Since I am not an native English speaking person, I do not know what it stands for. Perhaps you can tell me. Perhaps you can find out yourself:

Re: building a dict

2010-03-14 Thread Andreas Waldenburger
On Sun, 14 Mar 2010 08:36:55 -0400 Steve Holden st...@holdenweb.com wrote: Andreas Waldenburger wrote: On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler vicente.so...@gmail.com wrote: By the way, I suppose I am the OP. Since I am not an native English speaking person, I do not know what

building a dict

2010-03-13 Thread vsoler
Say that m is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a d dict where each key has an associated list whose first element is the count, and the second is the sum. If a 2- tuple contains a None value, it should be discarded. The expected

Re: building a dict

2010-03-13 Thread Jon Clements
On 13 Mar, 15:05, vsoler vicente.so...@gmail.com wrote: Say that m is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a d dict where each key has an associated list whose first element is the count, and the second is the sum. If a 2- tuple

Re: building a dict

2010-03-13 Thread Patrick Maupin
On Mar 13, 9:05 am, vsoler vicente.so...@gmail.com wrote: Say that m is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a d dict where each key has an associated list whose first element is the count, and the second is the sum. If a 2- tuple

Re: building a dict

2010-03-13 Thread Steve Holden
vsoler wrote: Say that m is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a d dict where each key has an associated list whose first element is the count, and the second is the sum. If a 2- tuple contains a None value, it should be

Re: building a dict

2010-03-13 Thread Jon Clements
On 13 Mar, 15:28, Patrick Maupin pmau...@gmail.com wrote: On Mar 13, 9:05 am, vsoler vicente.so...@gmail.com wrote: Say that m is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a d dict where each key has an associated list whose first

Re: building a dict

2010-03-13 Thread rurpy
On Mar 13, 8:28 am, Patrick Maupin pmau...@gmail.com wrote: On Mar 13, 9:05 am, vsoler vicente.so...@gmail.com wrote: Say that m is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a d dict where each key has an associated list whose

Re: building a dict

2010-03-13 Thread rurpy
On Mar 13, 9:13 am, ru...@yahoo.com wrote: On Mar 13, 8:28 am, Patrick Maupin pmau...@gmail.com wrote: On Mar 13, 9:05 am, vsoler vicente.so...@gmail.com wrote: Say that m is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a d dict

Re: building a dict

2010-03-13 Thread rurpy
On Mar 13, 9:26 am, ru...@yahoo.com wrote: That should be: d = {} for item in m:     key = item[0];  value = item[1]     if key is None or value is None: continue     if key not in dict:         d[key] = [1, value]     else:         d[key][0] += 1         d[key][1] += value That's it.

Re: building a dict

2010-03-13 Thread vsoler
On 13 mar, 18:16, ru...@yahoo.com wrote: On Mar 13, 9:26 am, ru...@yahoo.com wrote: That should be: d = {} for item in m:       key = item[0];  value = item[1]     if key is None or value is None: continue     if key not in dict:         d[key] = [1, value]     else:        

Re: building a dict

2010-03-13 Thread rurpy
On Mar 13, 2:42 pm, vsoler vicente.so...@gmail.com wrote: By the way, I suppose I am the OP. Since I am not an native English speaking person, I do not know what it stands for. Perhaps you can tell me. OP means Original Poster (the person who started the discussion) or sometimes Original

Re: building a dict

2010-03-13 Thread Andreas Waldenburger
On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler vicente.so...@gmail.com wrote: By the way, I suppose I am the OP. Since I am not an native English speaking person, I do not know what it stands for. Perhaps you can tell me. Perhaps you can find out yourself:

Efficiently building ordered dict

2010-02-22 Thread Bryan
using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster. Is there a better idiom that the code below to create an ordered dict from an unordered list

Re: Efficiently building ordered dict

2010-02-22 Thread Shashwat Anand
can avoid creating the first unordered dict just to get the ordered dict? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster

Re: Efficiently building ordered dict

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

Re: Efficiently building ordered dict

2010-02-22 Thread MRAB
dict? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster. Is there a better idiom that the code below to create an ordered dict from an unordered

Re: Efficiently building ordered dict

2010-02-22 Thread Bryan
avoid creating the first unordered dict just to get the ordered dict?  Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster

Re: Efficiently building ordered dict

2010-02-22 Thread MRAB
. Is there a way I can avoid creating the first unordered dict just to get the ordered dict? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster

Re: Efficiently building ordered dict

2010-02-22 Thread Arnaud Delobelle
just to get the ordered dict? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster. Is there a better idiom that the code below to create

Re: Efficiently building ordered dict

2010-02-22 Thread Mark Lawrence
. Is there a way I can avoid creating the first unordered dict just to get the ordered dict? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster

Re: Efficiently building ordered dict

2010-02-22 Thread Alf P. Steinbach
? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster. Is there a better idiom that the code below to create an ordered dict from an unordered

Re: Efficiently building ordered dict

2010-02-22 Thread Bryan
avoid creating the first unordered dict just to get the ordered dict?  Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster

Re: Efficiently building ordered dict

2010-02-22 Thread Arnaud Delobelle
On 22 Feb, 21:29, Bryan bryanv...@gmail.com 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

Re: Efficiently building ordered dict

2010-02-22 Thread Diez B. Roggisch
loop. Is there a way I can avoid creating the first unordered dict just to get the ordered dict? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become

Re: Efficiently building ordered dict

2010-02-22 Thread Bryan
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 using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure

Re: Efficiently building ordered dict

2010-02-22 Thread Diez B. Roggisch
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 using pop(k) to retrieve the values from the unordered dict while building

Re: Efficiently building ordered dict

2010-02-22 Thread MRAB
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 using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure

Re: Efficiently building ordered dict

2010-02-22 Thread Bryan
pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster.  Is there a better idiom that the code below to create an ordered dict from an unordered list

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:

Building a dict from a tuple of tuples

2010-02-20 Thread vsoler
Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column header. For example: d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } As you

Re: Building a dict from a tuple of tuples

2010-02-20 Thread MRAB
vsoler wrote: Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column header. For example: d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0,

Re: Building a dict from a tuple of tuples

2010-02-20 Thread vsoler
On Feb 20, 7:00 pm, MRAB pyt...@mrabarnett.plus.com wrote: vsoler wrote: Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column

Re: Building a dict from a tuple of tuples

2010-02-20 Thread MRAB
vsoler wrote: On Feb 20, 7:00 pm, MRAB pyt...@mrabarnett.plus.com wrote: vsoler wrote: Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column

Re: Building a dict from a tuple of tuples

2010-02-20 Thread vsoler
On Feb 20, 8:54 pm, MRAB pyt...@mrabarnett.plus.com wrote: vsoler wrote: On Feb 20, 7:00 pm, MRAB pyt...@mrabarnett.plus.com wrote: vsoler wrote: Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None,