Bug fixing in python solution