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


Groups > comp.lang.python > #80150 > unrolled thread

Dictionaries with variable default.

Started byAntoon Pardon <antoon.pardon@rece.vub.ac.be>
First post2014-11-03 12:04 +0100
Last post2014-11-03 12:04 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Dictionaries with variable default. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-11-03 12:04 +0100

#80150 — Dictionaries with variable default.

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2014-11-03 12:04 +0100
SubjectDictionaries with variable default.
Message-ID<mailman.15424.1415012757.18130.python-list@python.org>
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 "<stdin>", line 1, in <module>
TypeError: <lambda>() takes exactly 1 argument (0 given)

-- 
Antoon Pardon

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web