On 23 January 2013 07:26, moonhkt <moon...@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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to