Re: Dictionary Question

2007-02-09 Thread [EMAIL PROTECTED]
On 9 fév, 04:02, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 08 Feb 2007 23:32:50 -0300, Sick Monkey <[EMAIL PROTECTED]> > escribió: > > > db = {'[EMAIL PROTECTED]':'none', '[EMAIL PROTECTED]':'none', > > '[EMAIL PROTECTED]':'none', > > '[EMAIL PROTECTED]':'none',} > > > And I want to

Re: Dictionary Question

2007-02-08 Thread Gabriel Genellina
At Friday 9/2/2007 00:50, you wrote: Hey Gabriel, Please keep posting on the list - you'll reach a whole lot of people there... Thanks again for the help... but im still having some issues. For some reason the "domsrch.search(key)" is pointing to a memory reference... so when

Re: Dictionary Question

2007-02-08 Thread Gabriel Genellina
En Thu, 08 Feb 2007 23:32:50 -0300, Sick Monkey <[EMAIL PROTECTED]> escribió: > db = {'[EMAIL PROTECTED]':'none', '[EMAIL PROTECTED]':'none', > '[EMAIL PROTECTED]':'none', > '[EMAIL PROTECTED]':'none',} > > And I want to pull out all of the "gmail.com" addresses.. How would I do > this? > > N

Re: Dictionary question

2006-07-18 Thread Brian Elmegaard
"Nick Vatamaniuc" <[EMAIL PROTECTED]> writes: > if l[-1].setdefault(a+c, x+e) l[-1][a+c]=x+e Thanks for the answer. I will try it. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html Rugbyklubben Speed Scandinavian Open 7s Rugby http://www.rkspeed.dk -- http:

Re: Dictionary question

2006-07-18 Thread Brian Elmegaard
"Justin Azoff" <[EMAIL PROTECTED]> writes: > last[keytotal] = min(last.get(keytotal), valtotal) > comes close to working - it would if you were doing max. Thanks, I think this would help. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html Rugbyklubben Speed Scan

Re: Dictionary question

2006-07-18 Thread Brian Elmegaard
John Machin <[EMAIL PROTECTED]> writes: > 2. Put spaces around operators -- in general, RTFStyleGuide >http://www.python.org/dev/peps/pep-0008 I din't know it. Thanks. > Only you know what *really* meaningful names you should be using. I have better names in my running code. > mykey = a +

Re: Dictionary question

2006-07-18 Thread John Machin
On 18/07/2006 9:51 PM, Brian Elmegaard wrote: > Brian Elmegaard <[EMAIL PROTECTED]> writes: > > At least it was clumsy to post a wrong example. > This shows what = find clumsy. > > c=1 > x=2 > > l=list() > l.append(dict()) > l[0][5]=0 > > l.append(dict()) > > for a, e in l[-2].iteritems(): > #

Re: Dictionary question

2006-07-18 Thread Justin Azoff
Brian Elmegaard wrote: > for a, e in l[-2].iteritems(): > # Can this be written better? > if a+c in l[-1]: > if l[-1][a+c] l[-1][a+c]=x+e > else: > l[-1][a+c]=x+e > # I'd start with something like for a, e in l[-2].iteritems(): keytotal = a

Re: Dictionary question

2006-07-18 Thread Nick Vatamaniuc
Brian, You can try the setdefault method of the dictionary. For a dictionary D the setdefault work like this: D.setdefault(k, defvalue). If k not in D then D[k] is set to defvalue and defvalue is returned. For example: In [1]: d={} In [2]: d.setdefault(1,5) Out[2]:5 In [3]: d Out[3]:{1: 5} In y

Re: Dictionary question

2006-07-18 Thread Brian Elmegaard
Brian Elmegaard <[EMAIL PROTECTED]> writes: At least it was clumsy to post a wrong example. This shows what = find clumsy. c=1 x=2 l=list() l.append(dict()) l[0][5]=0 l.append(dict()) for a, e in l[-2].iteritems(): # Can this be written better? if a+c in l[-1]: if l[-1][a+c

Re: Dictionary question.

2005-04-23 Thread bserviss
A simple way to get individual values for the distribution is: d = {} for i in range( 0, 1000): j = random.randrange( 0, 100) if d.has_key(j): d[j] += 1 else: d[j] = 1 keys = d.keys() keys.sort() for key in keys: print key, ":", "*" * d[key] -- http://mail.pytho

Re: Dictionary question.

2005-04-21 Thread Kent Johnson
hawkesed wrote: Actually, I think I got it now. Here is what I did: for num in alist: ... if adict.has_key(num): ... x = adict.get(num) ... x = x + 1 ... adict.update({num:x}) A simpler way to do this last line is adict[num] = x ... else: ...

Re: Dictionary question.

2005-04-21 Thread Brian van den Broek
hawkesed said unto the world upon 2005-04-21 20:28: Actually, I think I got it now. Here is what I did: for num in alist: ... if adict.has_key(num): ... x = adict.get(num) ... x = x + 1 ... adict.update({num:x}) ... else: ... adict.updat

Re: Dictionary question.

2005-04-21 Thread hawkesed
Actually, I think I got it now. Here is what I did: >>> for num in alist: ... if adict.has_key(num): ... x = adict.get(num) ... x = x + 1 ... adict.update({num:x}) ... else: ... adict.update({num:1}) ... >>> adict {128: 2, 129: 2, 132: 1, 15

Re: Dictionary question.

2005-04-21 Thread hawkesed
Steve, thanks for the input. That is actually what I am trying to do, but I don't know the syntax for this in python. For example here is a list I want to work with as input: [101, 66, 75, 107, 108, 101, 106, 98, 111, 88, 119, 93, 115, 95, 114, 95, 118, 109, 85, 75, 88, 97, 53, 78, 98, 91, 115, 77

Re: Dictionary question.

2005-04-21 Thread hawkesed
Here is an example of the input list: [101, 66, 75, 107, 108, 101, 106, 98, 111, 88, 119, 93, 115, 95, 114, 95, 118, 109, 85, 75, 88, 97, 53, 78, 98, 91, 115, 77, 107, 153, 108, 101] Here is the code I am working on now: >>> for num in alist: ... if adict.has_key(num): ... x = adic

Re: Dictionary question.

2005-04-21 Thread Terry Reedy
"hawkesed" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > I am semi new to Python. Here is my problem : I have a list of 100 > random integers. I want to be able to construct a histogram out of the > data. So I want to know how many 70's, 71's, etc. I can't figure out > how

Re: Dictionary question.

2005-04-21 Thread Steve Holden
Simon Brunning wrote: On 21 Apr 2005 02:47:42 -0700, hawkesed <[EMAIL PROTECTED]> wrote: I am semi new to Python. Here is my problem : I have a list of 100 random integers. I want to be able to construct a histogram out of the data. So I want to know how many 70's, 71's, etc. I can't figure out ho

Re: Dictionary question.

2005-04-21 Thread Simon Brunning
On 21 Apr 2005 02:47:42 -0700, hawkesed <[EMAIL PROTECTED]> wrote: > I am semi new to Python. Here is my problem : I have a list of 100 > random integers. I want to be able to construct a histogram out of the > data. So I want to know how many 70's, 71's, etc. I can't figure out > how to do this.