Friday, September 11, 2015

count letters using dictionary get method

def countLetters(word):
    letterdict = {}
    for letter in word:
        letterdict[letter] = letterdict.get(letter, 0) + 1
    return letterdict