Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Count Letters in File
Posted by Matt Gerrans on December 08, 2001 at 6:37 PM
> Real amateur here. Need to make a short program that read a file called text.dat the displays the number of output of each character as: > Letter Frequency > A 23 etc. > Know its something to do with arrays and is suppose to be quite short. Its not an applet. > Any help would be appreciated. > Thanks.
x = {} for l in open('text.dat').readlines(): for c in l: if c in x.keys(): x[c] = x[c] + 1 else: x[c] = 1 for c in x.keys(): print '%c (%02x): %d' % (c,ord(c),x[c])
- mfg
Replies:
- this is? Chin Loong December 08, 2001 at 9:15 PM
(5)
- Python! Matt Gerrans December 09, 2001 at 1:40 AM
(4)
- python? Chin Loong December 09, 2001 at 8:30 AM
(3)
- Re: Python Brian Sanders December 10, 2001 at 9:02 AM
(2)
- Python, Perl-like? Matt Gerrans December 10, 2001 at 4:20 PM
(0)
- LOL Chin Loong December 10, 2001 at 9:46 AM
(0)
|