Created
January 30, 2012 21:34
-
-
Save joferkington/1706857 to your computer and use it in GitHub Desktop.
Example for babe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make up some data in nested lists | |
strain_data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] | |
# To make things a bit more readable, let's define a function that operates | |
# on a single list... | |
def zero(data): | |
"""Returns the difference between the items in "data" and its first item.""" | |
# This is a "list comprehension". It's basically a 1-line for loop | |
return [item - data[0] for item in data] | |
# Now, we'll apply "zero" to all of the lists in "strain_data"... | |
strain_data = [zero(item) for item in strain_data] | |
# And have a look at the result... | |
print strain_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment