Skip to content

Instantly share code, notes, and snippets.

@kinghat
Forked from blubberdiblub/list_comprehension.py
Created May 27, 2017 05:59
Show Gist options
  • Save kinghat/19d85223657d4d26790ed2946e4faf7f to your computer and use it in GitHub Desktop.
Save kinghat/19d85223657d4d26790ed2946e4faf7f to your computer and use it in GitHub Desktop.
Explaining list comprehension
new_list = [do_something_with(x) for x in old_list]
# is basically short for
new_list = []
for x in old_list:
new_list.append(do_something_with(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment