how I'd do it in python