dictionary initialization

Caleb Hattingh caleb1 at telkomsa.net
Thu Nov 25 21:48:52 EST 2004


Hi

I apologise, but I don't actually know what the problem is?  If you could  
restate it a little, that would help.

I didn't check the code I posted earlier;  This below is checked:
***
# Dont use a={}, just start as below
'>>> a['1']=0
'>>> a['1']+=1
'>>> a
{'1': 1}
***

Like I said, I am unsure of what your specific problem is?

Thanks
Caleb


On Thu, 25 Nov 2004 19:27:46 +0000 (UTC), Weiguang Shi  
<wgshi at namao.cs.ualberta.ca> wrote:

> Hi,
>
> In article <opsh1u2sow1js0xs at news.telkomsa.net>, Caleb Hattingh wrote:
>> ...
>> Dict entries accessed with 'string' keys,
> Not necessarily. And doesn't make a difference in my question.
>
>> ...
>>
>> Which feature specifically do you want justification for?
> Have it your way: string-indexed dictionaries.
>
>    >>> a={}
>    >>> a['1']+=1
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in ?
>    KeyError: '1'
>
> a['1'] when it referenced, is detected non-existent but not
> automatically initialized so that it exists before adding 1 to its
> value.
>
> Weiguang




More information about the Python-list mailing list