make it work with python 3+

I'm still at a beginner level when it comes to python, but I did manage to get this script working (minus the sort) in python 3+. Hopefully someone will share suggestions & improvements :)