Write the function thin_points(xs, ys, k). Assume xs and ys are sequences of numbers of the same length (lists, tuples or a range) and k is a positive int. A series with hundreds of thousands of points makes plt.plot slow and the picture no clearer, so before plotting we keep only every k-th point.
thin_points returns a tuple (new_xs, new_ys) of two lists: the points at index 0, k, 2k, … in their original order, plus the very last point if it is not already among them, so the drawn line still reaches the end of the data. Each kept x stays paired with its own y. The arguments must not be changed. Empty input gives ([], []).
xs = [0, 1, 2, 3, 4, 5, 6] ys = [0, 1, 4, 9, 16, 25, 36] print(thin_points(xs, ys, 3)) # ([0, 3, 6], [0, 9, 36]) print(thin_points(xs, ys, 4)) # ([0, 4, 6], [0, 16, 36]) print(thin_points(range(3), (5, 6, 7), 1)) # ([0, 1, 2], [5, 6, 7]) print(thin_points([], [], 2)) # ([], [])