same tricky problem in python