Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.