输入一行英文单词或者句子(不包含标点符号),对这行文本每个单词的首字母转换为大写,去掉重复单词,并且将单词按照字典序输出同时输出首字母
# encoding: utf-8
"""
@version: 1.0
@author: AusKa_T
@file: cc
@time: 2021/5/27 0027 14:58
"""
# 输入一行英文单词或者句子(不包含标点符号),对这行文本每个单词的首字母转换为大写,去掉重复单词,并且将单词按照字典序输出同时输出首字母
# 1 单词首字母转大写
def convert_initial(old: str) -> str:
new = ""
i = 0
while i < len(old):
if (i == 0) or (old[i - 1] == " "):
new += old[i].upper()
else:
new += old[i]
i += 1
return new
# 2 去除重复单词
def unique_list(l):
ulist = []
[ulist.append(x) for x in l if x not in ulist]
return ulist
# 3 单词排序
def sorted(inputWords):
inputWords.sort()
return inputWords
if __name__ == '__main__':
str = ' i am a boy a good boy,to see you and you !'
str = convert_initial(str)
str = ' '.join(unique_list(str.split()))
str = sorted(str.split(' '))
for i in str:
print(i[0])