Python for Rubyists, Part III: List Comprehensions

If you’ve been following along with this series, you already have a pretty solid foundation for getting out there and doing some programming in Python.

But there’s one tool that’s completely essential for programming in Python that doesn’t really have a parallel in Ruby, and that’s list comprehensions.

A brief refresher on lists: They’re a data structure that functions very similarly to arrays in other languages. For super basic applications, you can initialize them the boring way, like so: