Python Forum
looking 4 py code: file byte/character frequency - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: looking 4 py code: file byte/character frequency (/thread-1686.html)



looking 4 py code: file byte/character frequency - Skaperen - Jan-20-2017

the command line argument would be a filename in the coding used by the host system.  if the given name is what the platform normally uses to designate reading standard input or is missing, then the input will be stdin.  each byte/character of input will be counted, based on separate counters for each value.  output will be after end of file on input.  output will spell out the frequency of each byte/character of input and will show that frequency in some order sorted either by the byte/character value or the frequency count.

the code should work under python 3 as a minimum.  it can be made to work under both python 2 and python 3 by any known method of doing that (such as version checks), or by having separate code for each.


RE: looking 4 py code: file byte/character frequency - wavic - Jan-20-2017

Actually, collections.Counter do just that. Count the characters. Don't know for non printable ones.
I have somewhere a piece of code I've wrote for a yet unfinished project during my basic Python learning. It counts and sort by decr. frequency

Didn't know the collections module that time


RE: looking 4 py code: file byte/character frequency - Skaperen - Jan-20-2017

i believe collections.Counter works for anything that is hashable, just like a dictionary.

FYI, i am looking for done code.  in many cases i already know how and am looking for coding ideas like what issues the needs to handle.  i've already used collections.Counter in a couple projects.