We don’t give solutions as a forum policy. This has already been mentioned in this thread and explicitly stated in the linked post.
See the FAQ — I need help with my code! for tips on receiving help.
Also, I already gave half of the solution in the linked post, if you translate the code to Python you should be good to go.