I know I'm late to this discussion, but I tend to use something like: if ext not in res_dict: res_dict[ext] = 0
res_dict[ext] += 1 Cheers, Carl. On 16 December 2011 07:18, Christian Mascher <christian.masc...@gmx.de>wrote: > > On the other hand, >>> res_dict[ext] = res_dict.get(ext, 0) + 1 >>> >>> Isn't this at least as readable, and conceptually simpler? >> >> if ext in res_dict: >> res_dict[ext] += 1 >> else: res_dict[ext] = 1 >> >> > > I haven't done much coding in Python lately. And I found this much more > readable than the .get method which I forgot about. I positively didn't > understand the oneliner just by reading it over and over again. > > Of course I could easily have opened idle and looked up the .get method > online (or looked in a manual). > > The really good thing about Python is that so much of the core language > doesn't surprise you. One is able to write code which is understandable > even to people with very little experience or to yourself after not coding > in Python for years. Nobody has to write such clear-cut code all the time, > but at least it is possible with very little effort. > > Christian > > ______________________________**_________________ > Edu-sig mailing list > Edu-sig@python.org > http://mail.python.org/**mailman/listinfo/edu-sig<http://mail.python.org/mailman/listinfo/edu-sig> >
_______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig