python - 如何将列表的值与同一列表中的其他值进行比较?
问题描述
我正在处理我的代码。我想通过比较列表中包含的每个值来知道哪个值大于列表。以下是我创建的列表的示例。
list = ['1192:09:05', 1, -60, 5, -79, 4, -24, ..., n, n+1]
基于该列表,我想知道两者之间最伟大的一个list[2] list[4] list[6] list[n+1]
解决方案
如果我理解了,您想知道列表的最大值。
你可以试试这个:
list = ['1192:09:05', 1, -60, 5, -79, 4, -24, ..., n, n+1]
不得考虑此列表的第一个元素。
max = list[1]
for x in range(1,len(list)):
if list[x] > max:
max = list[x]
如果你想知道 list[2] list[4] list[6] list[n+1] 之间的最大数,你可以:
max = list[1]
for x in range(1,len(list),2):
if list[x] > max:
max = list[x]
我不知道'n'是什么,我帮不了你。
推荐阅读
- r - 如何将多个 csv 文件完全外部连接到 R 中的单个 data.table 中?
- image - 我对道具有问题并且要求我不知道是什么类型的问题。请帮忙。反应原生
- excel - 如何创建宏来更新基于 Web 的应用程序中的某些字段值?
- google-apps-script - SpreadSheet- 谷歌脚本 - 如何使用“findText()”方法在字符串中查找文本?
- django - 使用 Nginx 在同一域中具有不同位置的多个配置(React App)
- javascript - if else 与量角器如何使用
- google-sheets-api - 包含 API 密钥的 Google 表格的发布网址的正确语法是什么?
- azure - 无法使用变量在 Azure CLI 中设置 EventGrid 订阅高级筛选器
- google-app-engine - 是否可以使用 Google Cloud Logging 绘制历史数据图表?
- reactjs - React useState 无法分配 setState