dictionary initialization
Weiguang Shi
wgshi at namao.cs.ualberta.ca
Thu Nov 25 16:17:29 EST 2004
In article <lIydnVF-WvXK3TvcRVn-jA at rogers.com>, Dan Perl wrote:
>I don't know awk, so I don't know how your awk statement works.
It doesn't hurt to give it a try :-)
>
>Even when it comes to the python statements, I'm not sure exactly what the
> ...
I see your point.
>
>You're saying that in awk a['hello'] is initialized to 0.
More than that; I said awk recognizes a['hello']++ as an
arithmetic operation and initializes a['hello'] to 0 and add one to
it. (This is all guess. I didn't implement gawk. But you see my point.)
> That would not be justified in python. The type of b[1] is
> undetermined until initialization and I don't see why it should be
> an int by default.
In my example, it was b[1]+=1. "+=1" should at least tell Python two
things: this is an add operation and one of the operands is an
integer. Based on these, shouldn't Python be able to insert the pair
"1:0" into a{} before doing the increment?
Weiguang
More information about the Python-list
mailing list