您好,我已经编写了几个月的代码并且知道基础知识,但是我遇到了一个固定的会员问题,我找不到解决方案。
我有一个整数对列表的列表,我想删除其中包含“a”整数的列表。我认为使用集合是最简单的方法。下面是代码:
## This is the item to test against.
a = set([3])
## This is the list to test.
groups = [[3, 2], [3, 4], [1, 2], [5, 4], [4, 3]]
## This is a list that will contain the lists present
## in groups which do not contain "a"
groups_no_a = []
for group in groups:
group = set(group)
if a in group:
groups_no_a.append(group)
## I thought the problem had something to do with
## clearing the variable so I put this in,
## but to no remedy.
group.clear()
print groups_no_a
我也尝试过使用,s.issubset(t)
直到我意识到这测试了.s
t
谢谢!