Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46403

Re: Getting a callable for any value?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.069
X-Spam-Evidence '*H*': 0.87; '*S*': 0.01; 'subject:Getting': 0.07; 'assigning': 0.09; 'def': 0.12; 'lambda': 0.16; 'lambda:': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'trouble': 0.34; 'skip:d 20': 0.34; 'received:209.85': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; "you're": 0.61; 'name': 0.63; 'skip:n 10': 0.64; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=wG+j23zhlVJ+E/gfPvFdLKOfzW39KGkquQ/dMB2ZWG0=; b=BY2t5zIBGoWbgzNOhDUPAhEo4yzHe08S8BNRol5gkjeMHWGdmwZwBlDxF/un/sKvbM xGprueuKIBkZd4wRI5HN3LlQhzh3C2H/XO2wrZs6yb9HlHKDTYflgyEVtEmMwpgn9dKb 9WazC47Ze/5YcnJqnDJVqkHD+jcKLvx6BkA+OrERd6uVdGGiSbP/pvUdxn7j6ZTnLdBL 2Fw5jrE82FZzXPakpgItmTROTA8BCjQvHkD/n4o8cChL0zVKCgRKL+CL4FdSQQ7ofblh ugtWXCS0q+P0MHLZMMuxkGJBH9yST3PJ1KuVp55F7Pd4lE49jiePhqk/GoohPyqqkzYx 6WRQ==
X-Received by 10.68.176.197 with SMTP id ck5mr3997278pbc.165.1369851911895; Wed, 29 May 2013 11:25:11 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CAA=1kxRDu5CCL-MNj-K4hG2Xrex5tM6x-C=U+h5-Mwy3dqDuOw@mail.gmail.com>
References <CAA=1kxRDu5CCL-MNj-K4hG2Xrex5tM6x-C=U+h5-Mwy3dqDuOw@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 29 May 2013 12:24:31 -0600
Subject Re: Getting a callable for any value?
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2373.1369851922.3114.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369851922 news.xs4all.nl 15961 [2001:888:2000:d::a6]:47228
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46403

Show key headers only | View raw


On Wed, May 29, 2013 at 12:19 PM, Fábio Santos <fabiosantosart@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)

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Getting a callable for any value? Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-29 12:24 -0600

csiph-web