List Comprehensions in Python 3


10/21/21: This is old from when I was taking a Python course.

I often forget how to write list comprehensions, so I decided to write a blog post about it. The basic syntax goes like this:

list_name = [height for height in heights if height > 161]

If you want to manipulate it, you can do stuff like this:

fahrenheit = [celsius * (9 / 5) + 32 for celsius in celsius]

 


Leave a Reply