> answerDict=dict(map(lambda x: (str(x[1]),x[0]),map(lambda x: \ >> x.values(),Answer.objects.filter(fk_questionSet=1). \ >> filter(fk_question=1).values('widgetAnswer').order_by(). \ >> annotate(widgetCount=Count('widgetAnswer'))))) >> >> > The first time there's a suspected problem with this code, you'll probably > end up with a similar refactored set of 10-15 lines. I'm sure because I've > got code like that scattered throughout my codebase and that's what I end up > doing. The difference is that I rattle off the one-liners as part of the > original coding effort, and only break it out when there's a need to -- I'm > not striving to compact things into one-liners. >
Emile, Actually, I have already broken it out into 4 or 5 separate lines. The one-liner is cool for "Hey, look what I can do", but isn't for code maintenance. What I was striving for a happy medium between compactness and readability. > > BTW, doesn't > > > dict(map(lambda x: (str(x[1]),x[0]),map(lambda x:x.values() > > simply map the values of a dict back into a dict? > > I couldn't find a way to reverse the order of the elements to ultimately for a dictionary, so I resorted to this hack instead. -Tino
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor