c = {x: '' for x in a}

Raymond Hettinger vze4rx4y at verizon.net
Fri Mar 7 11:25:19 EST 2003


> > > What's wrong with this one though? It would totally make sense to
> > me...
> > >
> > > a = [1,2,3]
> > > c = {x: '' for x in a}
> >
> > Try this one :
> >
> > c = dict( [ ( x, '' ) for x in a ] )
> >
>
>
> and, in Python 2.3
>
>     c = sets.Set([1,2,3])

Also, in Python 2.3:

       c = dict.fromkeys(a, '')


Raymond Hettinger






More information about the Python-list mailing list