QUESTION IMAGE
Question
write a python program that prompts the user to enter a list of words and checks whether the list contains only unique elements. if not, print the duplicate words.
Step1: Get user - input list
word_list = input("Enter a list of words separated by spaces: ").split()
Step2: Create a dictionary to count word occurrences
word_count = {}
for word in word_list:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
Step3: Check for duplicates and print
duplicates = []
for word, count in word_count.items():
if count > 1:
duplicates.append(word)
if duplicates:
print("Duplicate words:", duplicates)
else:
print("The list contains only unique elements.")Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
The above Python code is the solution.