[Edu-sig] [edupython] Python in Education Advocacy Article
Michael Tobis
mtobis at gmail.com
Tue Mar 27 22:52:21 CEST 2007
Oof.
(Thanks.) :-}
Proving once again that eyeballing the test is not running the test!
As penance I have reduced it from seven lines to six. This one is actually
tested.
########
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(concord.items(), lambda x,y: cmp(-x[1],-y[1]) or
cmp(x[0],y[0]) )
print "\n".join( ["%s\t%s" % pair[-1::-1] for pair in result] )
# mt
########
On 3/26/07, Toby Donaldson <tjd at sfu.ca> wrote:
>
> Actually, it appears your code makes a common error: according to the
> problem specification, when frequencies are tied, they should be
> ordered alphabetically.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/edu-sig/attachments/20070327/5d52692f/attachment.htm
More information about the Edu-sig
mailing list