Doing some python practice about algorithm implementation, case solution.