接收字符串,返回每个字符最后一次出现,并顺序存入列表

编写函数,接收一个字符串,返回其中每个字符的最后一次出现,并按每个字符最后一次出现的先后顺序依次存入列表。例如,字符串'abcda'的处理结果为['b','c','d','a'],字符串'abcbda'处理结果为['c','b','d','a']


s = input('输入字符串:')
r = []
i = 1
for j in range(len(s)+1):
    if i < len(s):
        if s.count(s[i]) == 1:
            r.append(s[i])
        s = s[1::]
print(r)

img

如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢

a=input()
b=[]
for s in a:
    if s in b:
        b.remove(s)
    b.append(s)
print(b)
str1=input()
str2=str1[::-1]   #反转顺序
list1=[]
for i in range(len(str2)):
    if str2[i] not in list1:
        list1.append(str2[i])
print(list1[::-1]) #再次反转