updated
solution 2 in python