Sorting and Organization of letter frequency - python
Question: I'm trying to find a way to count the number of occurrences of letters in a
text file than display them in greatest to lowest depending upon there
frequency. This is what I have so far, please help get over this brain block.

    
    
    def me():
        info= input("what file would you like to select?")
        filehandle= open(info,"r")
        data=filehandle.read()
        case = data.upper()
        s=('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
        for i in range(26):
            print(s[i],case.count(s[i]))
    
    
    
    me()
    


Answer: Python has a nice built-in class for this: `collections.Counter`.

    
    
    In [8]: from collections import Counter
    
    In [9]: with open('Makefile', 'r') as f:
       ...:     raw = Counter(f.read())
       ...:
    
    In [10]: raw
    Out[10]: Counter({' ': 61, 'e': 46, 'p': 38, 'a': 29, '\n': 27, 'c': 27, 'n': 27, 'l': 26, 'd': 25, '-': 22, 's': 22, 'y': 22, 't': 20, 'i': 18, 'o': 18, 'r': 17, '.': 16, 'u': 13, '\t': 12, 'm': 12, 'b': 11, 'x': 10, 'h': 9, '/': 8, ':': 8, '_': 7, "'": 6, ';': 5, '\\': 5, 'f': 5, '*': 3, 'v': 3, '{': 3, '}': 3, 'k': 2, 'H': 1, 'O': 1, 'N': 1, 'P': 1, 'Y': 1, 'g': 1})
    

This is from the `pandas` library's `Makefile`, BTW. To sort them by their
frequency in descending order, do:

    
    
    In [22]: raw.most_common()
    Out[22]:
    [(' ', 61),
     ('e', 46),
     ('p', 38),
     ('a', 29),
     ('\n', 27),
     ('c', 27),
     ('n', 27),
     ('l', 26),
     ('d', 25),
     ('-', 22),
     ('s', 22),
     ('y', 22),
     ('t', 20),
     ('i', 18),
     ('o', 18),
     ('r', 17),
     ('.', 16),
     ('u', 13),
     ('\t', 12),
     ('m', 12),
     ('b', 11),
     ('x', 10),
     ('h', 9),
     ('/', 8),
     (':', 8),
     ('_', 7),
     ("'", 6),
     (';', 5),
     ('\\', 5),
     ('f', 5),
     ('*', 3),
     ('v', 3),
     ('{', 3),
     ('}', 3),
     ('k', 2),
     ('H', 1),
     ('O', 1),
     ('N', 1),
     ('P', 1),
     ('Y', 1),
     ('g', 1)]
    

I'm purposefully not using your exact data so that you can try and adapt my
solution to your problem.

