... comprehensions.

Python has a system that might simplify your code called comprehensions. They allow you to turn your nested for loop into an amazing single line of code. In this series of videos we'll highlight some useful ways to use them.


When dealing with dictionary comprehensions you should note that the keys of the dictionary must be unique.

Note how this dictionary has 7 key-value pairs.

{i: c for i, c in enumerate('abcdefa')}

While this dictionary only has 6.

{c: i for i, c in enumerate('abcdefa')}

Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider getting the newsletter.