Dictionary self lookup

Chris Rebert clp2 at rebertia.com
Wed Jun 24 06:05:40 EDT 2009

On Wed, Jun 24, 2009 at 2:39 AM, Norberto Lopes<shelika.void at gmail.com> wrote:
> Hi all.
> Assuming that python dictionaries already provide a bit of "shoot
> yourself in the foot", I think what I have in mind would not be so
> bad.
> What do you think of dictionaries having a self lookup in their
> declaration?
> Be able to do this:
> a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax
> instead of:
> a = { "foo" : "foo1" }
> a["bar"] = a["foo"]
> Maybe I'm murdering python syntax/philosophy right here so let me know
> if that's the case.

The idea sounds quite confusing and seems unnecessary.

Specifically, your proposal appears to contravene the following points
of the holy Zen of Python:

- Explicit is better than implicit.
- Readability counts.
- Special cases aren't special enough to break the rules.
- In the face of ambiguity, refuse the temptation to guess.
- If the implementation is hard to explain, it's a bad idea.


More information about the Python-list mailing list