Basic algorithms in Python