Lesson 6.12 - Optimal filtering of lists

I have a student who is filtering lists his own way. The program runs very slow. Does anyone have some suggestions on how I can explain to him why this program doesn’t run optimally?

Hi @jlester,

The reason the program is running slow is because the getColumn is actually taking a lot of time. While this doesn’t feel like a lot of time when we do it just once, (or 5-6 times), your student is calling the getColumn function on every row 5 times. This requires the computer to load that whole column and store it to be processed… when there are 610 rows, this is a lot of work!

Here’s a revised (much faster) version that doesn’t repeat the task of getting a column over and over. By moving this computation outside the for loop, the program speeds up!

1 Like