Algorithms in python