![图片[1]-如何判断列表中不包含某个元素-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5da187b944e0d334.jpg)
首先先定义一个列表,并在其中添加一些元素,然后来判断某一元素是否在其中。
例如
In[7]:test_list=[1,5,7,4,23,66] In[8]:a=25 In[9]:anotintest_list
以上实例输出结果为:
True
例如
frombisectimportbisect_left
#初始化列表
test_list_set=[1,6,3,5,3,4]
test_list_bisect=[1,6,3,5,3,4]
print("查看4是否在列表中(使用set()+in):")
test_list_set=set(test_list_set)
if4intest_list_set:
print("存在")
print("查看4是否在列表中(使用sort()+bisect_left()):")
test_list_bisect.sort()
ifbisect_left(test_list_bisect,4):
print("存在")
输出结果为
查看4是否在列表中(使用set()+in): 存在 查看4是否在列表中(使用sort()+bisect_left()): 存在原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
















































暂无评论内容