3.6.3.5. Exercise: Slicing lists 2#
Let’s get back to the spatial parameters of gait measured previously. For a given participant, we recorded this y
:
# y-coordinates of each heel strike, in meters
y = [0.13, 0.72, 1.29, 1.93, 2.55, 3.12, 3.71, 4.34, 4.95, 5.56]
If we know that the first element of y
always corresponds to the y-coordinate of the right foot, write a 2-line code that separates y
into two lists:
y_right
, which contains the y-coordinates of all heel strikes for the right footy_left
, which contains the y-coordinates all heel strikes for the left foot
Show code cell content
y_right = y[0::2]
y_left = y[1::2]
# Print the results
print(f"Right foot: {y_right}")
print(f"Left foot: {y_left}")
Right foot: [0.13, 1.29, 2.55, 3.71, 4.95]
Left foot: [0.72, 1.93, 3.12, 4.34, 5.56]