Project Description
Today’s project is all about cleaning up data — a crucial step in any real-world application. Your task is to build a Python program that removes duplicate values from a list provided by the user.
But here's the twist: instead of using a hardcoded list, your program should prompt the user to input a list of values separated by commas (for example: apple, banana, apple, orange
).
The program should then:
Convert the input into a list
Remove any duplicate entries
Print the cleaned list
And show how many duplicates were removed
This kind of functionality is useful in many real-life scenarios — think of cleaning up email lists, form submissions, tags in a blog system, or even log entries. It’s a great exercise in input handling, string manipulation, and basic data processing.
Expected Output
Here’s what a sample run of your program might look like:
💡 Hint
Don’t know where to start? Click the hint button to see how to turn user input into a list and ideas for removing duplicates.
𝌣 Solution
🔒 This solution is available to paid subscribers only.
✅ Includes both a set()
solution and a version that uses a loop to preserve the input order.
🚀 Want to keep leveling up?
Browse 200+ projects at dailypythonprojects.substack.com/archive and unlock all solutions by subscribing. Build real Python skills daily and transform how you learn — one project at a time.
I'm still learning Python and tried writing this code in a different way than solution. Could you please take a look and let me know if there are any improvements or better practices I should follow?
user_input = input("Enter items seprated by commas: ")
print(user_input)
count = 0
for item in user_input:
updated = user_input.split(",")
for num in updated:
appered = updated.count(num)
if appered > 1:
updated.remove(num)
print(updated)
count += 1
print(f"{count} duplicate(s) were removed")
Thanks
My solution:
def remove_duplicates():
user_input = input("Enter items separated by commas: ")
lst = [item.strip() for item in user_input.split(",")]
original_length = len(lst)
cleaned_list = sorted(set(lst))
cleaned_length = len(cleaned_list)
duplicates = original_length - cleaned_length
print(f"\nCleaned lst (duplicates removed): {cleaned_list}")
print(f"{duplicates} duplicate(s) were removed.")
remove_duplicates()