working python solution