s = set()
i = 0
while True:
user_input = input("enter words: ")
for words in user_input.strip().split():
words_from_list = words.strip().split()
for x in words_from_list:
s.add(x)
for i in s:
print(i)
the code above should show result like below
enter text: how are you dear
how 1
are 2
you 3
dear 4
enter text: how was your morning
how 1
your 5
was 6
morning 7
dear 4
random sequence is due to set the repeated element should have same sequence number
CodePudding user response:
I assume you wanted to do this:
s = set()
i = 0
while True:
user_input = input("enter words: ")
for words in user_input.strip().split():
words_from_list = words.strip().split()
for x in words_from_list:
s.add(x)
for i in s:
print(i)