Python Forum

Full Version: Distance between indicies of a list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how can i determine the distance between two indices in a list of values?

given a = [-1, 5, 4, 8, 3, 21, 18, 16, 3, 2, 3, 1, 4, 5, 17, 22, 36, 33, 34, 9, 1, -2]

how can i write a code which finds the distance between a[0] and a[3]?
What do you mean by distance?
If you mean position, then the distance is clearly 3.
If you mean difference between values, then it's a[3] - a[0]
Or are is it something entirely different you have in mind?
Basically i have to write a function which satisfies the following criteria:

The three possible outcomes are "Insufficient data", "Not detected" and a list of non overlapping indices that are greater than or equal to the given threshold value, and that satisfy the following criteria:
- an index is not selected if the value at the index is less than a value at one of it's overlapping indices.
- an index is not selected if it is overlapping with first or last index.
We say two indices are overlapping if the distance between them is less than the width of the pattern.

an example is this:

threshold = 15
pattern_width = 4
data_series = [-1, 5, 4, 8, 3, 21, 18, 16, 3, 2, 3, 1, 4, 5, 17, 22, 36, 33, 34, 9, 1, -2]
data_series = data_series + [-2, 4, -1, 7, 13, 12, 3, 1, 4, 5, 26, 22, 28, 27, 26, 2, 8, 6]

expected_answer = [5, 16, 34]