tag:blogger.com,1999:blog-11149365.post8148421232328957186..comments2024-03-23T04:34:59.089+00:00Comments on Go deh!: That history meme, in Python!Paddy3118http://www.blogger.com/profile/06899509753521482267noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-11149365.post-1262640097370431232015-06-12T14:00:50.532+01:002015-06-12T14:00:50.532+01:00Now, 7 years later, Python _has_ collections.Count...Now, 7 years later, Python _has_ collections.Counter, whose most_common method is what you need. ;-)Vekyhttps://www.blogger.com/profile/12207072339468136950noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-14368657816014926772008-04-18T06:05:00.000+01:002008-04-18T06:05:00.000+01:00Hi Justin,You just got me scrambling off searching...Hi Justin,<BR/>You just got me scrambling off searching for this unknown count module - which turns out to not be a standard module, which I guess is your point.<BR/><BR/>No pulling magic bunnies out of a hat! :-)<BR/><BR/><BR/>- Paddy.Paddy3118https://www.blogger.com/profile/06899509753521482267noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-44606958516984084482008-04-18T05:19:00.000+01:002008-04-18T05:19:00.000+01:00python isn't that bad, if you have helper modules ...python isn't that bad, if you have helper modules lying around...<BR/><BR/>history | python -c 'import sys,pprint,count; <BR/>pprint.pprint(count.count(x.split()[1] for x in sys.stdin)[:10])'<BR/><BR/>works for me :)Justin Ahttps://www.blogger.com/profile/07567730572096907480noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-23579486486931651872008-04-11T17:51:00.000+01:002008-04-11T17:51:00.000+01:00P.S.The two list comprehensions could be replaced ...P.S.<BR/>The two list comprehensions could be replaced by generator expressions but they stayed as it was easier to find my way around the line with the occasional ']' or '[' to 'anchor' me when reading the mush.<BR/><BR/>- Paddy.Paddy3118https://www.blogger.com/profile/06899509753521482267noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-79036428310943238912008-04-11T17:45:00.000+01:002008-04-11T17:45:00.000+01:00Hi David,Someone actually read that god-awful mess...Hi David,<BR/>Someone actually read that god-awful mess that I wrote - to such a degree that they understood it?!?!<BR/>Thanks for correction. I had not known that about groupby. (I have gone from reading about it and thinking that I will never use it - it must be there for completeness sake, to using groupby several times).<BR/><BR/>Hi fawcett,<BR/>I had seen pyline before but my post was just to show Pythons limitations. I do know my way around standard Unix tools, as well as Perl and AWK and tend to use them for my huge one-liners :-)<BR/><BR/>- Paddy.Paddy3118https://www.blogger.com/profile/06899509753521482267noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-16227795918842688142008-04-11T16:07:00.000+01:002008-04-11T16:07:00.000+01:00You might like my pyline script, which I wrote to ...You might like my <A HREF="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/437932" REL="nofollow">pyline</A> script, which I wrote to make Python work well in command pipelines. I use it all the time, and it's one of the first things I install on a new Unix box.Graham Fawcetthttps://www.blogger.com/profile/03670078611251538949noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-74284120355275178202008-04-11T15:13:00.000+01:002008-04-11T15:13:00.000+01:00You don't need the "lambda x:x". itertools.groupb...You don't need the "lambda x:x". itertools.groupby defaults to the identity function for the key. That makes it a bit shorter!David Goodgerhttps://www.blogger.com/profile/06673699859175469861noreply@blogger.com