Write a program that accepts a list of words as input and creates another list of these words after removing all duplicate words. Also print the list elements after sorting them alphanumerically.
Suppose the following input is supplied to the program:
[hello, world, and, practice, makes, perfect, and, hello ,world ,again]
Then, the list created should be:
[hello, world, and, practice, makes, perfect, again]
Answers
Answered by
1
Language:
Python
Program:
a=[]
while True:
inpu=input("Enter the value:")
if inpu=="stop":
break
else:
a.append(inpu)
nocopy=[]
for i in a:
if i in nocopy:
páss
else:
nocopy.append(i)
print(f"\nThe non ordered list : {nocopy}")
print(f"\nThe non ordered list : {sorted(nocopy)}")
Output:
Enter the value:hello
Enter the value:world
Enter the value:and
Enter the value:practise
Enter the value:makes
Enter the value:perfect
Enter the value:and
Enter the value:hello
Enter the value:world
Enter the value:again
Enter the value:stop
The non ordered list : ['hello', 'world', 'and', 'practise', 'makes', 'perfect', 'again']
The non ordered list : ['again', 'and', 'hello', 'makes', 'perfect', 'practise', 'world']
Explanation:
- Make a list of words from user input.
- Saves them in the new list if the word wasn't there, and if it was ignore past it.
- Print ordered and unordered form of the new list.
Attachment:
Attachments:
Similar questions