Skip to content

Instantly share code, notes, and snippets.

@joferkington
Created January 30, 2012 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joferkington/1706857 to your computer and use it in GitHub Desktop.
Save joferkington/1706857 to your computer and use it in GitHub Desktop.
Example for babe
# 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