小编Luk*_*P_8的帖子

如何从输入的字符串中打印唯一的单词

我有一些代码,我打算打印出将由用户输入的字符串中的所有唯一单词:

str1 = input("Please enter a sentence: ")

print("The words in that sentence are: ", str1.split())

unique = set(str1)
print("Here are the unique words in that sentence: ",unique)
Run Code Online (Sandbox Code Playgroud)

我可以让它打印出唯一的字母,但不能打印出唯一的单词。

python string set python-3.5

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

python-3.5 ×1

set ×1

string ×1