Default arg for dict() (was Re: Sorting distionary by value)

Steve Holden sholden at holdenweb.com
Fri Mar 29 08:28:02 EST 2002


"John Machin" <sjmachin at lexicon.net> wrote ...
> "Steve Holden" <sholden at holdenweb.com> wrote in message
news:<hpNo8.6269$Ou.4347 at atlpnn01.usenetserver.com>...
[ ... ]
> > This was a feature of the Icon language. But Icon had no explicit
literal
> > representation for dictionaries (or tables, as I think they were called)
as
> > far as I can remember, so it was easy to make the default value an
argument
> > to a constructor function. It's not obvious how you could indicate the
> > default without calling a method.
> >
>
> See above: freq = dict(default=0)
> I think that I'm proposing indicating the default by having a keyword
> argument ("default")on the new-in-2.2 constructor ("dict"); what do
> you think that I meant?

I knew what you meant, I was simply pointing out that dictionaries' literal
representations could notr specify a default value, which (I supposed) might
lead to VBScript-like horrors where all dictionaries (collections, in
VBScript) must be created by explicit addition.

However, Bength Richers suggestion:

> empty_dict_with_default = {:default}
> with_one_key_value_pair = {:default, key:value}
>
> A little tweak in the grammar might do it?

might well suffice, and wouldn't require huge changes to the grammar.

regards
 Steve








More information about the Python-list mailing list