所以我试图让这个程序要求用户输入并将值存储在数组/列表中.
然后,当输入空行时,它将告诉用户这些值中有多少是唯一的.
我建立这是出于现实生活的原因而不是问题集.
enter: happy
enter: rofl
enter: happy
enter: mpg8
enter: Cpp
enter: Cpp
enter:
There are 4 unique words!
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
# ask for input
ipta = raw_input("Word: ")
# create list
uniquewords = []
counter = 0
uniquewords.append(ipta)
a = 0 # loop thingy
# while loop to ask for input and append in list
while ipta:
ipta = raw_input("Word: ")
new_words.append(input1)
counter = counter + 1
for p in uniquewords:
Run Code Online (Sandbox Code Playgroud)
..那就是我到目前为止所做的一切.
我不确定如何计算列表中唯一的单词数?
如果有人可以发布解决方案,以便我可以从中学习,或者至少告诉我它会如何变得更好,谢谢!