try vs. has_key()
Carel Fellinger
cfelling at iae.nl
Tue Apr 27 15:05:42 EDT 1999
Hai Moshe Zadka,
sorry to react so late, but i'm a newbie to python, so it took me some time
to realise that i really don't understand what you are doing:)
In article <Pine.SUN.3.95-heb-2.07.990423140345.21577A-100000 at sunset.ma.huji.ac.il> you wrote:
> Note:
> This article is a non-commercial advertisement for the ``get'' method
> of dictionary objects.
> Brought to you by the object None and the method .append.
> d={}
> for word in words:
> d[word]=d.get(word, 0)+1
> Or, for logging:
> d={}
> for word in words:
> first_two=word[:2]
> d[first_two]=d.get(first_two, []).append(word)
this is the statement where i get lost. and when i try it with python 1.5.1
it doesn't work either. As far as i understand the append function it doesn't
return anything as it is just a shorthand for an assignment which to my
knowledge even in python 1.5.2 doesn't return values. or am i missing
something here? nonetheless, it looks great, and i sure hope it works too.
--
groetjes, carel
More information about the Python-list
mailing list