default behavior

Paul Rubin no.email at nospam.invalid
Thu Jul 29 14:18:39 EDT 2010


wheres pythonmonks <wherespythonmonks at gmail.com> writes:
> How do I build an "int1" type that has a default value of 1?
> [Hopefully no speed penalty.]
> I am thinking about applications with collections.defaultdict.

You can supply an arbitary function to collections.defaultdict.
It doesn't have to be a class.  E.g.

    d = collections.defaultdict(lambda: 1)

will do what you are asking.



More information about the Python-list mailing list