From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews1.google.com!not-for-mail From: duggar@mit.edu (Keith H Duggar) Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: 26 Sep 2004 19:12:00 -0700 Organization: http://groups.google.com Message-ID: References: <11b4d.3849$d5.30042@newsb.telia.net> NNTP-Posting-Host: 141.157.210.100 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1096251120 13960 127.0.0.1 (27 Sep 2004 02:12:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 27 Sep 2004 02:12:00 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:4238 Date: 2004-09-26T19:12:00-07:00 List-Id: > I've come to this thread late, so I'm not completely sure about the > exact specs of the code, but here's my take on a Python version. It > comes in at a svelt 10 lines, and I think it's quite readable. I'm sure > I'm missing something though. > > import sys > > words = {} > for line in sys.stdin.readlines(): > for word in line.split(): > words[word] = words.get(word, 0) + 1 > > words = [[x[1], x[0]] for x in words.items()] > words.sort() > words.reverse() > > for word in words[:10]: > print word[0], word[1] Sweet. Python get's my vote for most readable in this case. The "for ... in ..." construct is very nice. It saves a lot of time and a lot of error prone indexing code. Thanks for posting it.