set/dict comp in Py2.6

Paul Rubin http
Sat Oct 25 12:07:12 EDT 2008


bearophileHUGS at lycos.com writes:
> {x*x for x in xrange(10)}
> {x:x*x for x in xrange(10)}

I've always just used:

set(x*x for x in xrange(10))
dict((x,x*x) for x in xrange(10))

I didn't even realize that you could write sets with {...}.



More information about the Python-list mailing list