代码 s='helloworldhelloworldadfdfdeoofllffe' new_s=set(s) lst=list(new_s) lst.sort(key=s.index) print(''.join(lst)) 运行效果 helowrdaf 原来h在最前面,f在最后面。得到的结果也是这样。