I'm glad you were able to build your own working solution. I could see you were getting a lot of great help from plenty of people around here, especially AnomalousMonk and just wanted grasshopper!!! to think a bit more before posting complete working code for homework exercises.
When I was at university, something like 75% of first year students in one of my computing classes submitted the same code for an assignment (someone had copied a solution from a forum for a previous assignment and told their mates about it, leading to lots of people going to the same forums for "help" with the next assignment). They were all caught and individually warned that if it occurred again, the university would kick them out for plagiarism.