代码改变世界

python3--basic1

2019-07-12 23:10  yanux  阅读(244)  评论(0)    收藏  举报

 

L1 = [11, 22, 33,'a', 'b',(1,2,3)]
L2 = [33,'b','c',55,22,(1,2,3)]

# find out the list with the same elements
# L3 = []
# for i in L1:
#     if i in L2:
#         L3.append(i)
# print(L3)

# find out the elements in L1 but not in L2
# L3 = []
# for i in L1:
#     if i not in L2:
#         L3.append(i)
# print(L3)
# find out the elements in L2 but not in L1
# L3 = []
# for i in L2:
#     if i not in L1:
#         L3.append(i)
# print(L3)
# find out the elements (in L1 but not in L2) and (not in L1 but in L2)

L3 = []

for i in L2:
    if i not in L1:
        L3.append(i)
for i in L1:
    if i not in L2:
        L3.append(i)

print(L3)