default behavior

wheres pythonmonks wherespythonmonks at gmail.com
Thu Jul 29 14:35:06 EDT 2010


Thanks.  I presume this will work for my nested example as well.  Thanks again.

On Thu, Jul 29, 2010 at 2:18 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list