logo

... comprehensions: introduction



Notes

Let's say we want to create a new list from an old list.

old_list = [1, 2, 3, 4, 5]
new_list = []
for i in old_list:
    new_list.append(i * 2)
new_list

In this case we're doubling numbers. This simple operation can also be done on a single line instead.

[i * 2 for i in old_list]

In this series of video's we'll explore this coding pattern.

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



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