Iteration is something you absolutely have to grasp in order to master Python.
Itertools helps make iteration simpler and is incredibly powerful which is why you'll be learning it for the next 3 days!
For your first day, watch all of the videos up until the traffic lights app.
After watching the first 4 videos pop into your Python shell and start playing around with cycle()
, product()
, combinations()
and permutations()
.
Yep that's right! For your second day, use itertools to create a script that simulates traffic lights!
The idea is to perhaps... cycle (hint hint!) through the different colours of a set of traffic lights - red, amber and green - printing the name of the colour every time the cycle occurs.
For bonus points: traffic lights normally cycle between green and red based on traffic levels so you never know exactly when the change will happen. This is a great chance to throw some randomness into your script.
If you get absolutely stuck, watch the Traffic Lights video to see how we did it.
For your last day, I'm going to suggest you head to our Pybites Platform platform and take a few of the itertools themed Bites.
The following 3 links will get you free access to the Bites:
Form teams from a group of friends
Get all valid dictionary words for a draw of letters
You don't need to do them in any particular order, they're just there for you to learn something!
Be sure to share your last couple of days work on Twitter or Facebook. Use the hashtag #100DaysOfCode.
Here are some examples to inspire you. Consider including @talkpython and @pybites in your tweets.
See a mistake in these instructions? Please submit a new issue or fix it and submit a PR.