Dictionary question.

Kent Johnson kent37 at tds.net
Thu Apr 21 21:21:41 EDT 2005


hawkesed wrote:
> Actually,
>   I think I got it now. Here is what I did:
> 
>>>>for num in alist:
> 
> ... 	if adict.has_key(num):
> ... 		x = adict.get(num)
> ... 		x = x + 1
> ... 		adict.update({num:x})

A simpler way to do this last line is
adict[num] = x

> ... 	else:
> ... 		adict.update({num:1})
and
adict[num] = 1

Kent



More information about the Python-list mailing list