Skip to content

Instantly share code, notes, and snippets.

@reeddunkle
Created May 5, 2016 17:42
Show Gist options
  • Select an option

  • Save reeddunkle/bd9671b802ad53656dcccf34673ed427 to your computer and use it in GitHub Desktop.

Select an option

Save reeddunkle/bd9671b802ad53656dcccf34673ed427 to your computer and use it in GitHub Desktop.
List Comprehension Exercise
'''
This is hacky and ugly. It only works because both
lists are the same size, etc. etc.
Upon researching this, it seems that this is an example
when map() is actually way better and preferable.
There's also a function called zip() which does this,
but I haven't learned zip() yet.
I'll write about it when I do. I hear it's simple.
'''
NUMBERS = range(4)
NAMES = ['Rebecca', 'Georgi', 'Reed', 'Thom Yorke']
result = [(NUMBERS[i], NAMES[i]) for i in range(len(NUMBERS))]
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment