python - 如何编写代码来获取python列表中每个列表的最小值?
问题描述
我需要帮助编写代码,以帮助我获得 python 列表中每个列表的最低数量。然后在获得的最低值中,我必须以某种方式找到最低数中的最高数。我不允许调用内置函数min
或max
,或使用预先编写的模块中的任何其他函数。我该怎么做呢?我已经尝试使用以下代码:
for list in ells:
sort.list(ells)
解决方案
由于您不允许使用内置函数,因此您可以使用一个变量来跟踪您在遍历子列表时找到的最低数字,并使用另一个变量来跟踪您找到的最低数字中的最高值到目前为止,您遍历列表列表:
l = [
[2, 5, 7],
[1, 3, 8],
[4, 6, 9]
]
highest_of_lowest = None
for sublist in l:
lowest = None
for item in sublist:
if lowest is None or lowest > item:
lowest = item
if highest_of_lowest is None or highest_of_lowest < lowest:
highest_of_lowest = lowest
print(highest_of_lowest)
这输出:4
推荐阅读
- java - 如何在骆驼弹簧WS中捕获肥皂故障细节
- javascript - 在哪里放置快速验证消毒剂?
- python - 从 ASCII 代码中清除 python 字节
- pandas - 基于月差的组总数
- python - 如果它们存在于单独的元组中,则保留重复的元组值,但如果它们位于同一元组中,则仅保留唯一的元组值
- android - Android 上下文:“this”的类型不匹配
- python - 在这个程序中我得到属性错误?谁能解决这个错误并向我解释
- java - 调整另一个 jpanel 的大小时如何调整 jpanel 的大小
- excel - 复制值
- php - 在循环中完成 bindValue() 后无法执行 () 查询,但在为表中的每个列名独立运行 bindValue 时执行