def solution() -> str:
# your code here
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
def solution(s) -> str:
str_list = s.split(' ')
return ' '.join(
str_list[:1] + [str_list[i] for i in range(len(str_list)) if i > 0 and str_list[i - 1] != str_list[i]])
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
def solution(words: str) -> str:
# 将字符串转换为列表
words_list = words.split(' ')
# 复制列表
words_result = [x for x in words_list]
for i in range(len(words_list)-1):
if words_list[i] == words_list[i+1]:
# 列表中删除第一个等于words_list[i]的元素
words_result.remove(words_list[i])
# 返回结果,列表转换为字符串
return ' '.join(words_result)
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
def solution(mystr:str) -> str:
list_new = []
list1 = mystr.split(" ")
list_new.append(list1[0])
i = 0
while i <= len(list1)-2:
if list1[i] != list1[i+1]:
list_new.append(list1[i+1])
i=i+1
return " ".join(list_new)
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
def solution(string) -> str:
datas = string.split(' ')
n = len(datas)
for i in range(n - 1, 0, -1):
if datas[i] == datas[i - 1]:
del datas[i]
return ' '.join(datas)
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
def solution(sen: str) -> str:
words = sen.split()
reduced_words = []
for word in words:
if word not in reduced_words: reduced_words.append(word)
return ' '.join(reduced_words)
# your code here
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
def solution(words:str) -> str:
# your code here
words_list = words.split(" ")
new_words = [words_list[0]]
i, j = 0, 0
for _ in range(len(words_list)-1):
j += 1
if words_list[i] != words_list[j]:
new_words.append(words_list[j])
i = j
return " ".join(new_words)
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
def solution(line:str) -> str:
words = line.split(' ')
new_line = []
for w in words:
if len(new_line)==0 or w != new_line[-1]:
new_line.append(w)
return ' '.join(new_line)
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
assert solution("hogwarts is is is the best best is world") == "hogwarts is the best is world"
def solution(str_words: str) -> str:
res_list = []
for words in str_words.split(' '):
if words not in res_list:
res_list.append(words)
return ' '.join(res_list)
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("hogwarts is is is the best best") == "hogwarts is the best"
def solution(text) -> str:
new_text = text.split()
i = 0
while i < len(new_text)-1:
if new_text[i] == new_text[i+1]:
del new_text[i]
else:
i = i+1
print('new_text:',new_text)
return ' '.join(new_text)
assert solution("a b b b c d d d d") == "a b c d"
assert solution("alpha beta beta gamma") == "alpha beta gamma"
assert solution("is hogwarts is is is the best best") == "is hogwarts is the best"