笔记
s='helloworldhelloworldssgnjaghlhglhaslgh'
# (1)字符串拼接及not in
new_s=''
for item in s:
if item not in new_s:
new_s+=item # 拼接操作
print(new_s)
# 使用索引+not in
new_s2=''
for i in range(len(s)):
if s[i] not in new_s2:
new_s2+=s[i]
print(new_s2)
# 通过集合去重+列表排序
new_s3=set(s)
lst=list(new_s3)
lst.sort(key=s.index)
print(''.join(lst))
3550

被折叠的 条评论
为什么被折叠?



