Comprehending Comprehensions
09-08, 15:15–15:50 (Europe/Lisbon), Auditorium

Discover the immense potential of Python's list comprehensions, dictionary comprehensions, set comprehensions, and generator expressions, as we present them as an idiom that focuses on data transformations.

Using real-world examples, we'll demonstrate how these tools can streamline data manipulation and transformation tasks while enhancing code readability. We'll also provide insights on best practices and use cases to maximize their effectiveness.

By the end of this talk, you will be equipped to confidently harness the full potential of comprehensions and generator expressions, empowering you to create more expressive and elegant Python code. Join us on this exciting journey and level up your Python programming!


We will start by going over the full anatomy of a list comprehension, both by motivating the need for such a construct and by comparison to the equivalent for loop.

Then, we will take a look at some real-world examples of good list comprehensions, pointing out the qualities that make them elegant and expressive, which we will present as best practices.

Finally, we will use our understanding of list comprehensions to extend the syntax to dictionary and set comprehensions, as well as generator expressions.

Rodrigo has always been fascinated by problem solving and that is why he picked up programming – so that he could solve more problems. He also loves sharing knowledge, and that is why he spends so much time writing articles in his blog mathspp.com/blog, writing on Twitter @mathsppblog, and giving workshops and courses. You can also find his past talks on github.com/mathspp/talks.

His main areas of scientific interest are mathematics (numerical analysis in particular) and programming in general (with a preference for the Python and APL languages), but Rodrigo also enjoys reading fantasy books, watching silly comedy movies and eating chocolate.

This speaker also appears in: