Getting a callable for any value?

Ian Kelly ian.g.kelly at gmail.com
Wed May 29 14:24:31 EDT 2013


On Wed, May 29, 2013 at 12:19 PM, Fábio Santos <fabiosantosart at gmail.com> wrote:
> Are you sure you don't want to use a lambda expression? They are pretty
> pythonic.
>
> none_factory = lambda: None
> defaultdict_none_factory = lambda: defaultdict(none_factory)
>
> collections.defaultdict(defaultdict_none_factory)

Gah.  If you're going to go to the trouble of assigning a name to the
lambda, then just use a def statement:

def none_factory: return None
def defaultdict_none_factory: return defaultdict(none_factory)

collections.defaultdict(defaultdict_none_factory)



More information about the Python-list mailing list