输入一个列表,去掉列表中重复的数字,按原来次序输出!
输入格式:
在一行中输入列表
输出格式:
在一行中输出不重复列表元素
实现
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
from functools import reduce
def main():
#There is superfluous operation,but I just want to practice syntax.
#print(reduce(lambda x,y:x+' '+y,map(lambda x:str(x),set(eval(input())))))
i=0
ls=eval(input())
while i<len(ls):
#print(ls[i],end=' ')
while True:
try:
#You must pay attention to focus the difference between 'list.remove()' and 'list.__delitem__()'!!!
ls.__delitem__(ls.index(ls[i],i+1))
except Exception as e:
break;
finally:
pass
i+=1
print(reduce(lambda x,y:x+' '+y,map(lambda x:str(x),ls)))
#---
main()
输出
[4,7,5,6,8,6,9,5]
4 7 5 6 8 9