题目:
输入,包含重复元素的原始列表:[30,50,40,20,50,40]
返回:[30, 50, 40, 20]
解题思路:
1、定义一个新的空列表
2、遍历原始列表
3、加入判断条件
答案:
方法一:
list1=[30,50,40,20,50,40]
list2=[]
for i in list1:
if i not in list2:
list2.append(i)
print(list2)
----------------------------
[30, 50, 40, 20]
方法二:
list1=[30,50,40,20,50,40]
a = set(list1)
print(list(a))
---------------------
[40, 50, 20, 30]
标签:20,16,30,list1,50,40,列表,list2 From: https://www.cnblogs.com/LoLong/p/16849306.html