Sorting and Organization of letter frequency - python -
i'm trying find way count number of occurrences of letters in text file display them in greatest lowest depending upon there frequency. have far, please on brain block.
def me(): info= input("what file select?") filehandle= open(info,"r") data=filehandle.read() case = data.upper() s=('abcdefghijklmnopqrstuvwxyz') in range(26): print(s[i],case.count(s[i])) me()
this collections.counter
, most_common()
method for:
import collections import string def me(): info = input("what file select? ") filehandle = open(info, "r") data = filehandle.read().upper() char_counter = collections.counter(data) char, count in char_counter.most_common(): if char in string.ascii_uppercase: print(char, count) me()
a counter
dictionary counts number of occurrences of different items (in case, characters). char_counter.most_common()
gives pairs of characters , counts in sorted order.
we're interested in letters, check if character in string.ascii_uppercase
. string of letters z.
Comments
Post a Comment