import string alphabet = string.ascii_uppercase + " " def histogram(text): occ = {} for ch in text: if ch != "\n": i = alphabet.index(ch) count = occ.get(i+1, 0) #zaehle von 1 an occ[i+1] = count + 1 return occ fInp = open("caesar-secret.txt") krypto = fInp.read() fInp.close() print "Krypto:\n", krypto msg = histogram(krypto) print "Häufigkeiten:\n" print(msg)