python - 为什么我不能在 python 中使用'if A or B'函数得到正确的结果
问题描述
scores = [[100,90,98,88,65],[50,45,99,85,77]]
for i in range(len(scores)):
for j in range(len(scores[0])):
if scores[i][j] != min(scores[i]) or scores[i][j] != max(scores[i]):
print (scores[i][j])
Result
100
90
98
88
65
50
45
99
85
77
我想删除 100(第一行的最大值)和 45(第二行的最小值)。但它不起作用我认为'或'功能有问题。但我不知道它是什么。
解决方案
您还需要检查i
ie row 的值,您想要比较最大值i=0
和最小值i=1
,并且您需要通过and
运算符组合这些条件,然后是or
运算符。
scores = [[100,90,98,88,65],[50,45,99,85,77]]
for i in range(len(scores)):
for j in range(len(scores[0])):
if (i==1 and scores[i][j] != min(scores[i])) or (i==0 and scores[i][j] != max(scores[i])):
print (scores[i][j])
90
98
88
65
50
99
85
77
推荐阅读
- python - 如何从 scikit-learn 中的 TransformedTargetRegressor 管道中的经过训练的估计器访问属性?
- amazon-web-services - 在源代码控制中包含 aws-exports.js 文件是否错误/危险?
- flutter - 您上传的 APK 使用与之前的 APK 不同的证书进行签名。您必须使用相同的证书
- powershell - 我可以使用 Powershell 中的 New-NavContainer 在 Azure 中托管容器吗?
- android - 如何使用 Cloud Firestore 在 Android/Kotlin 中执行“点赞”功能?
- react-native - 反应本机键盘避免视图
- regex - 如何将 APA 中的引用编码为 excel 中的引用?
- html - Google 登录网站检测用户帐户并显示在 iframe/popup 中
- c++ - 用 Qt/C++ 中的一个代码构建两个略有不同的项目
- javascript - 等待服务器响应时如何添加进程栏