逆序 使用[::-1]更方便,因为不光可以对list起作用,对字符串也起作用。
reverse()只能对list起作用。对字符串不起作用
方法1:
result="" for i in input()[::-1]: if i not in result: result+=i print(result)
方法2:
while True: try: n = input() rev_list = list(n) rev_list.reverse() out_list = [] for x in rev_list: if x not in out_list: out_list.append(x) out_str = ''.join(out_list) print(out_str) except: break