Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80150 > unrolled thread
| Started by | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| First post | 2014-11-03 12:04 +0100 |
| Last post | 2014-11-03 12:04 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
Dictionaries with variable default. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-11-03 12:04 +0100
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Date | 2014-11-03 12:04 +0100 |
| Subject | Dictionaries 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
Back to top | Article view | comp.lang.python
csiph-web