Python - 测试列表的元素是否在其他列表的最小/最大范围内
当需要测试元素是否在最小/最大范围内时,将迭代列表元素,并检查它是否等于“最大值”值。
示例
下面是相同的演示
my_list = [5, 6, 4, 7, 8, 13, 15]
print("名单是: ")
print(my_list)
range_list = [4, 7, 10, 6]
my_result = True
for elem in range_list:
if elem!= max(my_list):
my_result = False
break
if(elem == True):
print("All the elements are in the min/max range")
else:
print("All the elements are not in the min/max range")输出结果名单是: [5, 6, 4, 7, 8, 13, 15] All the elements are not in the min/max range
解释
定义了一个列表并显示在控制台上。
定义了另一个整数列表。
变量被分配给“真”。
整数列表中的值被迭代。
如果原始列表中元素的最大值不等于整数列表中的任何元素,则结果变量设置为“假”。
它跳出循环。
最后,检查该值是否为“真”。
根据这一点,相关结果会显示在控制台上。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下