03-2 : Count characters in your string

Hashing

This is a CodeWars problem that requires returning a HashMap of the count of characters within a string.

Approach 1: HashMap

def count(s):
    letterCount = {}
    for c in s:
        letterCount[c] = 1 + letterCount.get(c, 0)
    return letterCount

Approach 2: HashMap (Dictionary Comprehension)

def count(s):
    return {c : s.count(c) for c in s}