I have written a function that counts the freq of characters in a file. The function works as intended, however, I would like to print the dictionary alphabetically by key. How do I do this the simplest way in Python.
Here is my function:
def characters(textfile):
textfile=open(textfile)
characters={}
for line in textfile:
for char in line:
if char in characters:
characters[char]+=1
else:
characters[char]=1
print(characters)