Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'argument': 0.05; 'received:134': 0.05; 'dependant': 0.16; 'given)': 0.16; 'key?': 0.16; 'subject:variable': 0.16; 'typeerror:': 0.16; 'obviously': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; '"",': 0.31; 'work:': 0.31; 'file': 0.32; '(most': 0.33; 'subject:with': 0.35; 'something': 0.35; 'but': 0.35; 'possible': 0.36; 'to:addr:python- list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'default': 0.69; 'hoping': 0.75; 'pardon': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqkEAL9gV1SGuA9G/2dsb2JhbABch0DSRwGBRQEBAQEBhSlVKgwCBRYLAgsDAgECAUsNCAKIPaNBj0KOOoYUgS2SYYFUBZMlilyHXY5zgUeCMoM2AQEB Date: Mon, 03 Nov 2014 12:04:48 +0100 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.0 MIME-Version: 1.0 To: Pyton List Subject: Dictionaries with variable default. Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415012757 news.xs4all.nl 2844 [2001:888:2000:d::a6]:55615 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80150 Is it possible to have a default dictionary where the default is dependant on the key? I was hoping something like this might work: >>> m = defaultdict(lambda key: key+1) But it obviously doesn't: >>> m[3] Traceback (most recent call last): File "", line 1, in TypeError: () takes exactly 1 argument (0 given) -- Antoon Pardon