On Mar 18, 1:30 pm, Kottiyath <n.kottiy...@gmail.com> wrote: > When we say readability counts over complexity, how do we define what > level of complexity is ok? > For example: > Say I have dict a = {'a': 2, 'c': 4, 'b': 3} > I want to increment the values by 1 for all keys in the dictionary. > So, should we do:>>> for key in a: > > ... a[key] = a[key] + 1 > or is it Ok to have code like: > dict(map(lambda key: (key, a[key] + 1), a)) > > How do we decide whether a level of complexity is Ok or not?
The second alternative is: - unreadable (took me 10 seconds to parse vs 1 for the former). - slower (makes a function call on every round). - broken (creates a new dict instead of modifying the original in place). Really, there's not much of a dilemma here. George -- http://mail.python.org/mailman/listinfo/python-list