Skip to content

Instantly share code, notes, and snippets.

@kidchenko
Created September 17, 2013 23:49
Show Gist options
  • Save kidchenko/6602387 to your computer and use it in GitHub Desktop.
Save kidchenko/6602387 to your computer and use it in GitHub Desktop.
List Comprehension Sintaxe.
new_list = [x for x in range(1,6)]
# => [1, 2, 3, 4, 5]
doubles = [x*2 for x in range(1,6)]
# => [2, 4, 6, 8, 10]
doubles_by_3 = [x*2 for x in range(1,6) if (x*2)%3 == 0]
# => [6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment