Hi to all, after two months I decided to give Python one more chance. Here is a little code snippet about counting number of words in text file. (Under word I assume any combination of letters and numbers delimited by standard separators " .,\n\t"
file = open ( "Test.txt", "r" )
text = file.read ( )
file.close ( )
word_freq ={ }
word_list = string.split ( text )
for word in word_list:
count = word_freq.get ( string.lower ( word ), 0 )
word_freq[string. lower ( word )] = count + 1
keys = word_freq.keys ( )
keys.sort ( )
for word in keys:
print word, word_freq[word]
Can this be done a little more elegant?