List comprehensions and generators are in my top 5 favorite Python features leading to clean, robust and Pythonic code.
Welcome to this lesson. In today's videos you will learn two powerful techniques you can use in Python: list comprehensions and generators.
I prepared a Jupyter notebook so you can follow along with this lesson.
Look at your code and see if you can refactor it to use list comprehensions. Same for generators. Are you building up a list somewhere where you could potentially use a generator?
My notebook has an exercise to sink your teeth in. Please try it and tomorrow I will discuss the solution.
I will detail the solution of yesterday's exercise in my notebook
Today if you have time left, I encourage you to try another exercise on our platform:
If you still have time left, or you prefer to practice generators check out this cool blog code challenge: Code Challenge 11 - Generators for Fun and Profit
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.