Did #40 in python