Implementing some basic algos in Python