a clean way to define dictionary

Michael Chermside mcherm at mcherm.com
Thu Jun 19 08:35:22 EDT 2003


Alexander Schmolck writes:
> Maybe I'm a bit blinkered, but right now I can't see how
> 
>     dict(foo=1, bar='sean')
> 
> is so much better/more convinient than
> 
>     {'foo':1, bar:'sean'}

I think you've answered your own question. If you know that a particular
dict is going to have simple string keys, then it's kind of a pain to
remember to type the quotes around the keys. As evidence, I point to
your own post, which should have been:
      {'foo':1, 'bar':'sean'}
Now, I'm not fully convinced that the new syntax useful enough to be
worth having multiple ways to do it (one of which breaks as soon as
you have a non-identifier key), but in the situation where it works,
it's clearly (a little bit) more convenient.

-- Michael Chermside






More information about the Python-list mailing list