Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37482

Re: Increase value in hash table

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <moonhkt@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'output': 0.04; 'val': 0.07; 'works.': 0.07; 'cc:addr:python-list': 0.10; 'def': 0.10; 'benjamin': 0.16; 'cc:name:python list': 0.16; 'line.split()': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'keyerror:': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; "haven't": 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'error': 0.30; 'file': 0.32; 'print': 0.32; 'entry': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'skip:p 20': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'skip:" 10': 0.40; '2013': 0.84; 'dict.': 0.84; 'oscar': 0.84; 'subject:Increase': 0.84; 'subject:value': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=eorL/GL4OmijrjyhIt8tcSgaNrS33iI/p+/1r1sIyy4=; b=iV+/sefOawzP5Rkh+BsVFDy14vChK19Qrl75u7MHGxpFilMGInOqEXkJXMSj6iR45U mQ8xJFw+x9gstS2PHo48oHQgqKV46myIcB280+UjVoESc9t5c59ast/+e4Htd/9MDO3A 42fYqdVaWVlAjgAFedTvzg8JaxrNfuCXk1xqKXBgG75IdqQSxj4ie48e+r2WQeXsoBSh KhC5z0Y5Tdf6fBDOOrp8qATeGAQhOSL4aH6uRQ2W8FLMtQ4Dd/BKPbAi2B3BdkEPf0S7 A+WihNgLhc5uO20V+NRyAIDZsQYVaki8rV336Tkc3ifCvPCwinfvRChFK5r9pkk22ZCC cB+g==
MIME-Version 1.0
X-Received by 10.152.147.103 with SMTP id tj7mr1696893lab.54.1358955189406; Wed, 23 Jan 2013 07:33:09 -0800 (PST)
In-Reply-To <CAHVvXxRhwS4cLxF9d9kOzJVgvHxdtw0rFDzA4j7DF0xkpYnmnQ@mail.gmail.com>
References <32d316a1-8551-4cb2-871f-b0a653c7d2f6@u7g2000yqg.googlegroups.com> <CAHVvXxRhwS4cLxF9d9kOzJVgvHxdtw0rFDzA4j7DF0xkpYnmnQ@mail.gmail.com>
Date Wed, 23 Jan 2013 23:33:09 +0800
Subject Re: Increase value in hash table
From moonhk <moonhkt@gmail.com>
To Oscar Benjamin <oscar.j.benjamin@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.903.1358955191.2939.python-list@python.org> (permalink)
Lines 71
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358955191 news.xs4all.nl 6847 [2001:888:2000:d::a6]:55073
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37482

Show key headers only | View raw


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] = printque[val] + 1
             if key in "/dev/null":
                 val='null'
                 if val not in printque:
                    printque[val] = 1
                 else:
                    printque[val] = printque[val] + 1


On Wed, Jan 23, 2013 at 6:12 PM, Oscar Benjamin
<oscar.j.benjamin@gmail.com> wrote:
> On 23 January 2013 07:26, moonhkt <moonhkt@gmail.com> 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] =  printque[val] + 1
>>
>> I have below error
>>   File "xprintlogchk.py", line 78, in chklog
>>     printque[val] =  printque[val] + 1
>> KeyError: 'nan'
>
> 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
>
>
> Oscar



-- 
moonhkt
GMT+8

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Increase value in hash table moonhkt <moonhkt@gmail.com> - 2013-01-22 23:26 -0800
  Re: Increase value in hash table Chris Rebert <clp2@rebertia.com> - 2013-01-22 23:34 -0800
    Re: Increase value in hash table moonhkt <moonhkt@gmail.com> - 2013-01-23 01:23 -0800
  Re: Increase value in hash table Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-23 10:12 +0000
    Re: Increase value in hash table Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-23 10:47 +0000
      Multiple postings [was Re: Increase value in hash table] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-23 21:54 +1100
        Re: Multiple postings [was Re: Increase value in hash table] rusi <rustompmody@gmail.com> - 2013-01-23 06:00 -0800
    Re: Increase value in hash table Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-23 10:46 +0000
    Re: Increase value in hash table Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-23 10:46 +0000
    Re: Increase value in hash table Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-23 10:47 +0000
  Re: Increase value in hash table moonhk <moonhkt@gmail.com> - 2013-01-23 23:33 +0800
    Re: Increase value in hash table moonhkt <moonhkt@gmail.com> - 2013-01-23 07:39 -0800
      Re: Increase value in hash table Dave Angel <d@davea.name> - 2013-01-23 17:35 -0500
  Re: Increase value in hash table Vito De Tullio <vito.detullio@gmail.com> - 2013-01-24 19:30 +0100

csiph-web