2024-04-19 15:39:35 发布
网友
我需要帮助来搜索列表中某个范围内的值
list.append((5,range(10,15))) if (5,12) in list : Print("yes")
使用all
all
例如:
l = (5,range(10,15)) check = (5,12) if all([check[0] == l[0] and check[1] in l[1]]): print("Ok")
输出:好的
也许你在找这样的东西?你知道吗
mylist = [] mylist.extend(list(range(10, 15)) + [5]) check_list = [5, 12] if all([z in mylist for z in check_list]): print('yes')
输出:
yes
把第二个范围列为一个列表,你可以这样做-
result = any(elem in list1 for elem in list2)
其中结果是True或False
True
False
使用
all
例如:
输出:好的
也许你在找这样的东西?你知道吗
输出:
yes
把第二个范围列为一个列表,你可以这样做-
其中结果是
True
或False
相关问题 更多 >
编程相关推荐