Re: building a dict

2010-03-14 Thread Andreas Waldenburger
On Sun, 14 Mar 2010 08:36:55 -0400 Steve Holden wrote: > Andreas Waldenburger wrote: > > On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler > > 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 ca

Re: building a dict

2010-03-14 Thread Steve Holden
Andreas Waldenburger wrote: > On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler > 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: > > http://www

Re: building a dict

2010-03-13 Thread Andreas Waldenburger
On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler 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: http://www.urbandictionary.com/define.php?term=op /W

Re: building a dict

2010-03-13 Thread rurpy
On Mar 13, 2:42 pm, vsoler 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 Post, depending on contex

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, 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 Tha

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 wrote: > > > > > On Mar 13, 9:05 am, 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

Re: building a dict

2010-03-13 Thread rurpy
On Mar 13, 8:28 am, Patrick Maupin wrote: > On Mar 13, 9:05 am, 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, a

Re: building a dict

2010-03-13 Thread Jon Clements
On 13 Mar, 15:28, Patrick Maupin wrote: > On Mar 13, 9:05 am, 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

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

Re: building a dict

2010-03-13 Thread Patrick Maupin
On Mar 13, 9:05 am, 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 No

Re: building a dict

2010-03-13 Thread Jon Clements
On 13 Mar, 15:05, 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

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 from a tuple of tuples

2010-02-20 Thread vsoler
On Feb 20, 8:54 pm, MRAB wrote: > vsoler wrote: > > On Feb 20, 7:00 pm, MRAB 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

Re: Building a dict from a tuple of tuples

2010-02-20 Thread MRAB
vsoler wrote: On Feb 20, 7:00 pm, MRAB 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 header. For example: d={ (

Re: Building a dict from a tuple of tuples

2010-02-20 Thread vsoler
On Feb 20, 7:00 pm, MRAB 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 > > header.

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, (u'b',u'y')

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 c