Turning a for loop into a list comprehension

Опубликовано: 28 Сентябрь 2024
на канале: Python Morsels
401
17

If you're new to comprehensions, I recommend copy-pasting your way from a loop to comprehension to anchor your existing understanding of "for" loops with your new knowledge of comprehensions.

Read an article version of this video at https://pym.dev/turning-loop-list-com...

Find more Python screencasts at https://pym.dev/screencasts/

00:00 A for loop that builds up a new list
00:17 Copy-pasting our way into a comprehension
01:09 Making comprehensions that filter items
02:05 Turning nested for loops into a comprehension
02:32 What if directly copy-pasting isn't possible?
03:49 Summary