Posted in Python onNovember 24, 2019
该算法实现对列表中大于某个阈值(比如level=5)的连续数据段的提取,具体效果如下:
找出list里面大于5的连续数据段:
list = [1,2,3,4,2,3,4,5,6,7,4,6,7,8,5,6,7,3,2,4,4,4,5,3,6,7,8,9,8,6,1]
输出:
[[6, 7], [6, 7, 8], [6, 7], [6, 7, 8, 9, 8, 6]]
算法实现:
# -*- coding: utf-8 -*- """ -------------------------------------------------------- # @Version : python3.6 # @Author : wtg # @File : data_search.py # @Software: PyCharm # @Time : 2018/12/17 14:44 -------------------------------------------------------- # @Description: -------------------------------------------------------- """ def data_search(data, level): list = [] temp = [] for i in range(len(data)): if data[i] > level: temp.append(data[i]) else: list.append(temp) temp = [] return [i for i in list if i] if __name__ == '__main__': list = [1,2,3,4,2,3,4,5,6,7,4,6,7,8,5,6,7,3,2,4,4,4,5,3,6,7,8,9,8,6,1] ret = data_search(list, 5) print("input: ",list) print("output: ",ret)
效果如下:
以上这篇python找出列表中大于某个阈值的数据段示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。
python找出列表中大于某个阈值的数据段示例
- Author -
偶尔也吃鸡声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@