py vs php: stemming

I’ve been porting some PHP to python during SuperHappyDevHouse and was amazed at how little code I needed to write since python makes list manipulation a breeze.

Today I was working on stemming (ala Porter Stemming algorithm). reviewsby.us uses stemming in the search engine to make queries:

Stemming turns hello everybody how are you guy's into a collection 'everybodi', 'gui', 'hello'. To produce this in php I do the following:

With some magic python:

The magic here is list mappings. Learning about them, they don’t seem that great, but as soon as you start coding you stop using a lot of for loops.

I’m sure my PHP can be cleaned up and reduced as well, but its fun exploiting the magic of languages.