DEV Community

Discussion on: Post an Elegant Code Snippet You Love.

Collapse
 
luizgtvsilva profile image
Luiz Gustavo da Silva • Edited

Using this:

new_list = [x for x in old_list if x > 0]
Enter fullscreen mode Exit fullscreen mode

Instead of this:

new_list = []
for x in old_list:
    if x > 0:
        new_list.append(x)
Enter fullscreen mode Exit fullscreen mode

It's so beautiful hahaha