Crag的博客

自学编程

jeapedu 133 集合的習題6

链接: https://pan.baidu.com/s/1KZNLIIY_Ag5R2aJxgEueBg 密码: udnp

# 7 delete elements of list b in list a
a = [1, 3, 3, 5, 1, 6]
b = [1, 3, 7, 9]
print(a)
print(b)
for x in a:
    if x in b:
        a.remove(x)
print('left', a)
print(b)
print('----')
a = [1, 3, 3, 5, 1, 6]
b = [1, 3, 7, 9]
print(a)
print(b)
i = 0
while i < len(a):
    if a[i] in b:
        a.remove(a[i])
        i -= 1
    i += 1
print('left', a)
print(b)    
print('----')
a = [1, 3, 3, 5, 1, 6]
b = [1, 3, 7, 9]
print('a', a)
print('b', b)
sa = set(a)
print(sa)
sb = set(b)
print(sb)
ab = sa.intersection(sb)
print('ab', ab)
lab = list(ab)
print('lab', lab)
for x in lab:
    c = a.count(x)
    for y in range(0, c):
        a.remove(x)
print(a)
阅读更多
个人分类: jeapedu
上一篇jeapedu 132 集合的習題5
下一篇jeapedu 134 集合的習題6方法二
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭