Skip to content

Instantly share code, notes, and snippets.

@alexmuller
Created August 14, 2019 08:20
Show Gist options
  • Save alexmuller/e23b3a77ba2469c2cb7b346afd5b711c to your computer and use it in GitHub Desktop.
Save alexmuller/e23b3a77ba2469c2cb7b346afd5b711c to your computer and use it in GitHub Desktop.
>>> range(5)
[0, 1, 2, 3, 4]
>>> sum(range(5))
10
>>> def is_even(x):
... return x % 2 == 0
...
>>> [x for x in range(5) if is_even(x)]
[0, 2, 4]
>>> sum([x for x in range(5) if is_even(x)])
6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment