Why doesn't Python 2.6 have set literals and comprehensions or dict comprehensions? [closed]

StackOverflow https://stackoverflow.com/questions/345356

  •  19-08-2019
  •  | 
  •  

Question

Python 2.6 was basically a stepping stone to make converting to Python 3 easier. A lot of the features destined for Python 3 were implemented in 2.6 if they didn't break backward compatibility with syntax and the class libs.

Why weren't set literals ({1, 2, 3}), set comprehensions ({v for v in l}), or dict comprehensions ({k: v for k, v in d}) among them? In particular dict comprehensions would have been a great boon... I find myself using the considerably uglier dict([(k, v) for k, v in d]) an awful lot lately.

Is there something obvious I'm missing, or was this just a feature that didn't make the cut?

Was it helpful?

Solution

It wasn't done because nobody took the time to do it. There are bugs opened for months, and no one commented on them:

So it wasn't important enough for anybody to care, probably.

OTHER TIPS

All these are syntax/grammar changes. Such changes are traditionally introduced first in a Python x.y version with a from __future__ import … statement, and implemented at least on Python x.(y+1) version. Such a transition hasn't happened yet for these changes.

Technically, I've answered your "why".

Now, if you meant, “why didn't anyone take the time to suggest, support and implement something that I would like to have in 2.x also, even if they don't know about it since I never tried to suggest/support backporting those syntax enhancements in either comp.lang.python or Python-Dev and I never tried to even read the PEPs?”, then the answer lies in you too, and you can offer an answer yourself.

HTH

BTW, you shouldn't use the dict([(k,v) for k,v in d]) form, but the dict((k,v) for k,v in d). More efficient. Why create an intermediate list?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top