Python code for some algorithm practice