eg "hello it is a nice day today and it is hot"
the output should be: ("hello" "it" "is" "a" "nice" "day" "today" "and" "hot") NOTE: the set only has unique words from the sentence, no repeating words
I tried it myself but it says its wrong:
opening_line="It was the best of times, it was the worst of times"
def get_vocabulary(word_list):
words = word_list.split()
dickens_words = set()
dickens_words.add(words)
return words
print(get_vocabulary(opening_line))
You're adding the entire list as a single element to the set. Instead, you could construct a set from list, which would add all the words individually to the set:
def get_vocabulary(word_list):
return set(word_list.split())
The problem is add() accept only one element.
Try adding the link when you create the set
dickens_words = set(words)
A = list(input("statement:").strip().split(' '))
print (' '.join(list(dict.fromkeys(A))))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.