题目:
输入:
- 原始列表:[3,5,7,9,11,13]
- 移除元素:[7,11]
返回:
- [3,5,9,13]
思路:
1、遍历移除元素列表
2、判断迭代变量中是否在原始列表中,若在则删除。
答案:
方法一:循环遍历
list1 = [3,5,7,9,11,13]
remove1 = [7,11]
for i in remove1:
if i in list1:
list1.remove(i)
print(list1)
-----------------------
[3, 5, 9, 13]
方法二:推导式
data = [i for i in list1 if i not in remove1]
print(data)
标签:11,13,15,list1,remove1,列表,移除 From: https://www.cnblogs.com/LoLong/p/16846181.html