Python solution