To be honest I like the Python solution best.  It's also probably faster.