Python Forum
looking 4 py code: file byte/character frequency
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looking 4 py code: file byte/character frequency
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020