![]() |
Help With Function to search a list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Help With Function to search a list (/thread-9682.html) |
Help With Function to search a list - johnissa - Apr-23-2018 Hi i need help with writing a function which will return a list of values under the following conditions: example: [python] def example(a, width, lower_limit): a = [-1, 5, 4, 8, 3, 21, 18, 16, 3, 2, 3, 1, 4, 5, 17, 22, 36, 33, 34, 9, 1, -2] a = a + [-2, 4, -1, 7, 13, 12, 3, 1, 4, 5, 26, 22, 28, 27, 26, 2, 8, 6] lower_limit = 15 Sorry this is the correct set of conditions: Could someone please me because i am struggling to find a way to even start this problem. RE: Help With Function to search a list - Larz60+ - Apr-23-2018 what have you tried so far? show your code as is, and where the problem lies. RE: Help With Function to search a list - johnissa - Apr-24-2018 what i have now is a for loop which find every number which is greater than or equal to threshold. 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] greater_than_threshold = [i for i in data_series if i >= threshold]overlapping = when the distance between indices is < pattern_width Next i want to go through each value in the greater_than_threshold list and if chosen value at index < value within an overlapping index, then disregard that value Could you please help me on how i can do this without using numpy or other complex python built in functions? |