def character_frequency(filename): try: f = open(filename) except OSError: return None characters = {} for line in f: for char in line: characters[char] = characters.get(char, 0) + 1 # get the entry for char or create a new entry with value 0 if there is no entry for char yet f.close() return characters()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter