python集合问题

功能:输入n个整数,对这n个整数去重之后按原顺序输出。
要求:一行中输入n个整数。其中1≤n≤100,每个数的范围1≤x≤n。整数之间以空格间隔,去重之后按原顺序输出。
提示:
1.输入n个整数,以空格分隔,保存在列表lst中,输入语句为lst=[int(x) for x in input().split(" ")]
2.将列表lst转换为集合myset
3.将集合myset转换为列表newlst
4.对列表newlst按列表lst中的元素顺序排序(key=lst.index)
5.遍历列表newlst,输出各元素值(以空格分隔)
测试用例:
输入:
3 1 2 1 2
输出:
3 1 2

lst = [int(x) for x in input().split(" ")] # 输入n个整数
myset = set(lst) # 转换为集合并去重
newlst = list(myset) # 转换为列表
newlst.sort(key=lst.index) # 按lst中元素顺序排序
print(" ".join([str(x) for x in newlst])) # 输出去重后的列表元素,以空格分隔