Actually, it appears your code makes a common error: according to the
problem specification, when frequencies are tied, they should be
ordered alphabetically. But your code orders tied frequencies in
reverse, e.g.
7 which # oops: wrong order
7 this
7 there
7 one
7
Seven lines seems reasonable to me:
##
import sys
concord = {}
for word in [token.lower() for token in open(sys.argv
[1],"r").read().split()]:
concord[word] = concord.get(word,0) + 1
result = sorted([(item[1],item[0]) for item in concord.items
()],reverse=True)
for pair in result:
Michael,
On the sigcse list there was recently a coding challenge
(http://www.cs.duke.edu/csed/code) that asked for solutions to a word
frequency problem in various languages. I believe the author is
planning to eventually list all the solutions received (entries came
in many different languages);
Dear Python-in-Education types
For Python to gain the ground it ought to in educational settings will not
happen automatically.
To do my part, I have decided that my first article in the Python Papers
should be about comparing Python to other common first languages for
learning and teaching. I'd