[Tutor] Misc question about scoping

Tino Dai oberoc at gmail.com
Fri Jun 4 18:26:20 CEST 2010

> I have a distinct feeling that you would simply love a language like lisp.

LOL, it's actually on the list of things to do. And hear that one will become a
better programmer once they learn LISP.

> The code is succinct, and it may very well be called elegant in some
> sense of the word. I might call it "clever," which in the python
> community is not generally meant as a compliment. Readability counts,
> you see, and I find that piece of code nigh impossible to read. I
> would suggest changing the map calls into generator expressions, and
> using a few temporary variables for clarity. That should keep most of
> the brevity but increase legibility:
> answers = Answer.objects.filter(fk_questionSet=1,
> fk_question=1).values('widgetAnswer')
> answers = answers.order_by().annotate(widgetCount=Count('widgetAnswer'))
> values = (x.values() for x in answers)
> answerDict = dict((str(v[1]), v[0]) for v in values)

I am always fighting the battle - more compact vs more readable :) . A couple of
questions that I have: Why generators over map? Is it somehow more efficient
under the covers or is it for readability purposes? I noticed that you
took out the
lambda function too (not much good without a map/filter/reduce) to replace
with the generator function. Also could you give me some instances
where a generator
would be used in a real situation? I have already read the stuff on
doc.python.org about


More information about the Tutor mailing list