Python implementation for a few problems