Python Lists filter() vs List Comprehension – Which is Faster?

[Spoiler] Which function filters a list faster: filter() vs list comprehension? For large lists with one million elements, filtering lists with list comprehension is 40% faster than the built-in filter() method. To answer this question, I’ve written a short script that tests the runtime performance of filtering large lists of increasing sizes using the filter() … Read more

Python One-Liners: Sampling A 2D Python List (to Speed Up Machine Learning)

This is a tutorial video from my new book “Python One-Liners” with NoStarch press (San Francisco 2020). Grab your Python One-Liner Superpower now! (Amazon Link) Here’s the code that shows you how to sample a two-dimensional Python list—including only every other list element in the resulting two-dimensional Python list. All of this happens in a … Read more