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

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Fri Mar 29 08:57:08 EST 2002


----- Original Message -----
From: "Steve Holden" <sholden at holdenweb.com>


> "John Machin" <sjmachin at lexicon.net> wrote ...
>
> > 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.

But do we REALLY need it?  Another new semantic feature, another altered
basic behavior.  Python is so cool because it is compact (linguistically)
and easy to grasp.  Each new use of punctuation makes it more complex and
Perl-like.

Writing a class to simulate a dictionary with default value is simple,
and left as an exercise for the reader :-)

Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
http://newcenturycomputers.net






More information about the Python-list mailing list