set/dict comp in Py2.6

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Oct 25 11:07:35 CEST 2008


On Sat, 25 Oct 2008 01:13:08 -0700, bearophileHUGS wrote:

> I'd like to know why Python 2.6 doesn't have the syntax to create sets/
> dicts of Python 3.0, like:
> 
> {x*x for x in xrange(10)}
> {x:x*x for x in xrange(10)}

Maybe nobody asked for it?

Personally, I don't see the advantage of set and dict comprehensions. I 
think the value of them is very marginal, not worth the additional syntax.

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

work perfectly well using the existing syntax.


-- 
Steven




More information about the Python-list mailing list