#100DaysOfCode in Python Transcripts
Chapter: Days 16-18: List comprehensions and generators
Lecture: Concepts: what did we learn
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
Let's look at what we've learned so far. List comprehensions. For both ways of doing a loop and conditional,
0:10
we loop over list and store all the modifications in a new list. Five lines of code. The more Pythonic ways to use a list comprehension.
0:20
One line of code. And it reads like English. We went through another sample cleaning up a word list, and you can do multiple checks.
0:29
in the conditional part over list comprehension. Secondly, generators. The simplest generator would be something like this.
0:40
For in range, yield the value. Generators, pause. So, after every call it stops at the yield, and comes back. Use a generator to build up a sequence.
0:54
Here I made a bunch of options for a fictional website. And instead of building up a list in the function, we use the yield statement
1:03
to just generate a sequence of items. And lastly, we look at list and generators, and we saw that when your data set grows
1:16
your really want to know about generators because the items are lazily loaded, not taking up the whole memory footprint. And that's it for the basics.
1:27
And now it's your turn for day two and three to get more practical exercise.