‘’’
列表去重
定义一个函数 def remove_element(m_list):,将列表[10, 1, 2, 20, 10, 3, 2, 1, 15, 20, 44, 56, 3, 2, 1]去除重复元素
‘’’
def remove_element(m_list):
#定义一个空列表
new_list=[]
#循环判断某个元素是不是在新的列表中,如果在列表中,就不添加,如果不在新的列表中,将元素添加到新的列表中
for i in m_list:
# print(i)
if i not in new_list:
new_list.append(i)
# print(new_list)
return new_list
remove_list=[10, 1, 2, 20, 10, 3, 2, 1, 15, 20, 44, 56, 3, 2, 1]
print(remove_element(remove_list))