Basic try-except structure

PHOTO EMBED

Sun Mar 28 2021 06:39:16 GMT+0000 (UTC)

Saved by @FlorianC #python

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()
        
content_copyCOPY