Re: Increase value in hash table

2013-01-24 Thread Vito De Tullio
moonhkt wrote: > Data file > V1 > V2 > V3 > V4 > V4 > V3 > > How to using count number of data ? > > Output > V1 = 1 > V2 = 1 > V3 =2 > V4 = 2 import collections with open(data_file) as f: print(collections.Counter(f.readlines())) it's a start -- ZeD -- http://mail.python.org/mai

Re: Increase value in hash table

2013-01-23 Thread Dave Angel
On 01/23/2013 10:39 AM, moonhkt wrote: On Jan 23, 11:33 pm, moonhk wrote: Works. For some definition of 'works" prndev = line.split() # print line for key in prndev : if key in 'lpr': This test will fire if key is the letter "l", or the letter "p"

Re: Increase value in hash table

2013-01-23 Thread moonhkt
On Jan 23, 11:33 pm, moonhk wrote: > Works. > >      prndev = line.split() >          # print line >          for key in prndev : >              if key in 'lpr': >                 val = prndev[5].replace("-P","") >                 if val not in printque: >                    printque[val] = 1 >  

Re: Increase value in hash table

2013-01-23 Thread moonhk
Works. prndev = line.split() # print line for key in prndev : if key in 'lpr': val = prndev[5].replace("-P","") if val not in printque: printque[val] = 1 else: printque[val] =

Re: Multiple postings [was Re: Increase value in hash table]

2013-01-23 Thread rusi
On Jan 23, 3:54 pm, Steven D'Aprano wrote: > Steven D'Aprano wrote: > > I *swear* I only sent it once. Now Now Steven! Good boys dont swear. > Arrgggh, it's happened again. Sorry for the multiple posts folks... > Trying this time with a different news client. Its a law of the universe called k

Multiple postings [was Re: Increase value in hash table]

2013-01-23 Thread Steven D'Aprano
Steven D'Aprano wrote: [snip content] Arrgggh, it's happened again. Sorry for the multiple posts folks, I *swear* I only sent it once. Trying this time with a different news client. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Increase value in hash table

2013-01-23 Thread Steven D'Aprano
On Wed, 23 Jan 2013 10:12:25 +, Oscar Benjamin wrote: > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 Another way of

Re: Increase value in hash table

2013-01-23 Thread Steven D'Aprano
On Wed, 23 Jan 2013 10:12:25 +, Oscar Benjamin wrote: > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 Another way of

Re: Increase value in hash table

2013-01-23 Thread Steven D'Aprano
On Wed, 23 Jan 2013 10:12:25 +, Oscar Benjamin wrote: > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 Another way of

Re: Increase value in hash table

2013-01-23 Thread Steven D'Aprano
On Wed, 23 Jan 2013 10:12:25 +, Oscar Benjamin wrote: > You can't retrieve the value of printque[val] if you haven't yet added > an entry with the key val to the dict. Try this: > > if val not in printque: > printque[val] = 1 > else: > printque[val] = printque[val] + 1 Another way of

Re: Increase value in hash table

2013-01-23 Thread Oscar Benjamin
On 23 January 2013 07:26, moonhkt wrote: > Hi Al > > I have Data file have below > > Data file > V1 > V2 > V3 > V4 > V4 > V3 > > How to using count number of data ? > > Output > V1 = 1 > V2 = 1 > V3 =2 > V4 = 2 > > > > # Global Veriable > printque = {} > in def have below > > printque[val] = prin

Re: Increase value in hash table

2013-01-23 Thread moonhkt
On Jan 23, 3:34 pm, Chris Rebert wrote: > On Jan 22, 2013 11:31 PM, "moonhkt" wrote: > > > > > > > > > > > > > Hi Al > > > I have Data file have below > > > Data file > > V1 > > V2 > > V3 > > V4 > > V4 > > V3 > > > How to using count number of data ? > > > Output > > V1 = 1 > > V2 = 1 > > V3 =2 >

Re: Increase value in hash table

2013-01-22 Thread Chris Rebert
On Jan 22, 2013 11:31 PM, "moonhkt" wrote: > > Hi Al > > I have Data file have below > > Data file > V1 > V2 > V3 > V4 > V4 > V3 > > How to using count number of data ? > > Output > V1 = 1 > V2 = 1 > V3 =2 > V4 = 2 Construct a frequency table using collections.Counter: http://docs.python.org/2.7

Increase value in hash table

2013-01-22 Thread moonhkt
Hi Al I have Data file have below Data file V1 V2 V3 V4 V4 V3 How to using count number of data ? Output V1 = 1 V2 = 1 V3 =2 V4 = 2 # Global Veriable printque = {} in def have below printque[val] = printque[val] + 1 I have below error File "xprintlogchk.py", line 78, in chklog print