[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zen of Python



Avi Bryant wrote:
> What's the equivalent Python idiom?

d.setdefault("spam", 42)

or

if d.has_key("spam"):
    d["spam"] = 42

or, if you insist:

if_absent_put(d, "spam", lambda: 42)

> My guess is that it will be either less regular, or less explicit,
> or both.

whatever.

</F>