ways to declare empty set variable

Nick Craig-Wood nick at craig-wood.com
Wed Feb 13 14:30:04 EST 2008


Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
>  bearophileHUGS at lycos.com writes:
> 
> > Missing that, I think dict() and set() and tuple() and list()
> 
>  I often use these myself. They're slightly more explicit, which can
>  help when I want the reader not to have to think too much, and they're
>  not particularly verbose because the names are well-chosen and
>  short.

You can also do this with the dict() syntax

dict(a = 1, b = 2, c = 3)

which I find a lot more readable than

{ 'a' : 1, 'b' : 2, 'c' : 3 }

In a lot of circumstances.

The syntax isn't so great when you set things which aren't valid
keywords though...

eg

{ (1,2,3) : 'a', (4,5,6) : 'b' }

vs

dict([ ((1,2,3), 'a'), ((4,5,6), 'b') ])

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list