I've created these 3 functions to count the value of letters in a word.
All these functions are functionally the same.
Apparently List comprehensions (count_word3) are usually seen as the most pythonic in these situations. But to me it is the least clear of the 3 examples.
Have I stumbled across something that is so simple that lambdas are acceptable here or is "the right thing to do" to use the list comprehension?
Or is there something better?
def count_word1(w): def count(i, a): return i + ord(a) - 64 return reduce(count, w, 0) def count_word2(w): return reduce(lambda a,b : a + ord(b) - 64, w, 0) def count_word3(w): vals = [ord(c) - 64 for c in w] return sum(vals)