Python 中如何删除一个列表 List 中多个符合条件的元素
1个回答
展开全部
l3=range(10)
l2=range(5)
l3=[i for i in l3 if i not in l2]
运行结果:
Python 2.7.12 (default, Nov 22 2016, 17:23:24)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l3=range(10)
>>> l3
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> l2=range(5)
>>> l2
[0, 1, 2, 3, 4]
>>> l3=[i for i in l3 if i not in l2]
>>> l3
[5, 6, 7, 8, 9]
l2=range(5)
l3=[i for i in l3 if i not in l2]
运行结果:
Python 2.7.12 (default, Nov 22 2016, 17:23:24)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l3=range(10)
>>> l3
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> l2=range(5)
>>> l2
[0, 1, 2, 3, 4]
>>> l3=[i for i in l3 if i not in l2]
>>> l3
[5, 6, 7, 8, 9]
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询