在Python中的列表中查找大于0的第一个和最后一个值
它是基于太阳能测量系统的列表,因此在一天的头几个小时里为0,在一天的最后几个小时中为0,因此我有兴趣获得最小值和最大值大于0;示例:
total_solar = [0,0,0,0,0,100,200,200,200,200,200,200,200,120,0,0,0,0,0,0,0]
It is a list based on a solar measurement system so in the first hours of the day it will be 0 and in the last hours of the day it will be 0, so I am interested in obtaining the minimum and maximum value greater than 0; example:
total_solar=[0,0,0,0,0,100,200,200,300,200,200,120,0,0,0,0,0]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用列表理解删除零,然后使用
min
和max
函数。You can remove the zeros with list comprehension then use the
min
andmax
functions.我鼓励您自己尝试,您通过编程学习编程。这绝对看起来像编程练习。
但是在这里,对于初学者来说,另一个更简单的解决方案。
I encourage you to try by yourself, you learn programming by programming. This definitely looks like programming exercise.
But here another solution simpler for beginner.
使用发电机理解来过滤值
Use a generator comprehension to filter the values, for ex