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


Groups > comp.lang.python > #81760

Setting default_factory of defaultdict to key

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <larry.martell@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'key.': 0.09; 'undefined': 0.09; "'xxx'": 0.16; 'accesses': 0.16; 'defaultdict': 0.16; 'key)': 0.16; 'key?': 0.16; 'lambda': 0.16; 'subject:key': 0.16; 'tried:': 0.16; 'to:name:python-list@python.org': 0.22; 'define': 0.26; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; 'work.': 0.31; 'keys': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'i.e.': 0.36; 'subject:skip:d 10': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'subject:Setting': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=R+JrW4bPk/N+uwkkUAoOehaueY01oSuSXdJm2urvk4I=; b=zMNypAq/F1wLKL72m8Ffswes04LFDr9JbmWye/gN9Zj8kfXEdBDfUOjh6mpTCGMTb1 MJKa4Elw/XBd9vvx7u8+lLev2Xo0Q/AZxNCpHyPM1C+GrDP2KbcBjpECys5NpMHnFnEb ZUIBdfRp47amNGs9Pt9KuMLSqS0RJb5jg2OSTVF5iFsetBf6FHz/lhUrhgzmBVM452re 8K/gBe118H1fwNeUQ/R0idr8p0V1ruHy738MHQDpmJfASOjdtGiUSTVFoSMiwyUBURjM ksYuSWmMU90UVH2dLfEtdLfrpTCNXJC0fOIrDqdFMJAn/NszeECjZwAMiO0viZMgxIk0 NVOg==
MIME-Version 1.0
X-Received by 10.195.17.231 with SMTP id gh7mr96140843wjd.21.1417457104658; Mon, 01 Dec 2014 10:05:04 -0800 (PST)
Date Mon, 1 Dec 2014 13:05:04 -0500
Subject Setting default_factory of defaultdict to key
From Larry Martell <larry.martell@gmail.com>
To "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16457.1417457107.18130.python-list@python.org> (permalink)
Lines 12
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417457107 news.xs4all.nl 2863 [2001:888:2000:d::a6]:34597
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81760

Show key headers only | View raw


Is there a way to set the default_factory of defaultdict so that
accesses to undefined keys get to set to the key?

i.e. if d['xxx'] were accessed and there was no key 'xxx' then
d['xxx'] would get set to 'xxx'

I know I can define a function with lambda for the default_factory,
but I don't see how to access the key. I tried:

d = defaultdict(lambda: key)

But that did not work.

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


Thread

Setting default_factory of defaultdict to key Larry Martell <larry.martell@gmail.com> - 2014-12-01 13:05 -0500

csiph-web