Re: Please explain collections.defaultdict(lambda: 1)

2007-11-06 Thread Duncan Booth
"metaperl.com" <[EMAIL PROTECTED]> wrote: > Per http://docs.python.org/lib/defaultdict-examples.html > > It seems that there is a default factory which initializes each key to > 1. So by the end of train(), each member of the dictionary model will > have value >= 1 > > But why wouldnt he set the

Re: Please explain collections.defaultdict(lambda: 1)

2007-11-06 Thread Paul McGuire
On Nov 6, 8:54 am, "metaperl.com" <[EMAIL PROTECTED]> wrote: > I'm readinghttp://norvig.com/spell-correct.html > > and do not understand the expression listed in the subject which is > part of this function: > > def train(features): > model = collections.defaultdict(lambda: 1) > for f in fe

Please explain collections.defaultdict(lambda: 1)

2007-11-06 Thread metaperl.com
I'm reading http://norvig.com/spell-correct.html and do not understand the expression listed in the subject which is part of this function: def train(features): model = collections.defaultdict(lambda: 1) for f in features: model[f] += 1 return model Per http://docs.python.org/