Mainly Tech projects on Python and Electronic Design Automation.

Tuesday, September 18, 2012

Big-up the Python collections.Counter class massif'

Hey guys, I've known about the Counter class for some time, and did my usual playing around with it when it first came out.

Yesterday I created a player of the Pig Dice Game and needed to create statistics on what strategy had won. I hit on the idea of sending the result in order of the winning strategy of each game played to an instance of the Counter class. A subsequent call of winners.most_common(), (at the end of the prog), collated the statistics I needed.

Today, at work, I was generating a more involved set of stats and I used counter.most_common in a similar way. These calls save me a lot of code which I appreciate, so I'd just like to thank you in a more public fashion.

Cheers people :-)


Followers

Subscribe Now: google

Add to Google Reader or Homepage

Go deh too!

whos.amung.us

Blog Archive