def handle(s): t = s.split() ret = [] for k,v in enumerate(t): if k<len(t)-1 and t[k+1] != v: ret.append(v) ret.append(t[-1]) return " ".join(ret)
str_list=input().spilt(' ') for i in range(len(str_list)): #这里的长度评论里都是len-2,why? if str_list[i]==str_list[i+1]: del str_list[i+1] print(' '.join(str_list)) #评论里还有另一种方法,看不懂?
error_str = "This is is a desk" correct_str = [] for i in error_str.split(): if i not in correct_str: correct_str.append(i) print(" ".join(correct_str))
para = 'This is is a a desk desk.'.split(' ') print(para) d = [] for word in para: if word not in d: d.append(word) print(' '.join(d))