Python: Remove the duplicate numbers from a given list of numbers
Python Basic - 1: Exercise-110 with Solution
Write a Python program to remove duplicate numbers from a given list of numbers.
Sample Solution:
Python Code:
def unique_nums(nums):
return [i for i in nums if nums.count(i)==1]
nums = [1,2,3,2,3,4,5]
print("Original list of numbers:",nums)
print("After removing the duplicate numbers from the said list:")
print(unique_nums(nums))
nums = [1,2,3,2,4,5]
print("\nOriginal list of numbers:",nums)
print("After removing the duplicate numbers from the said list:")
print(unique_nums(nums))
nums = [1,2,3,4,5]
print("\nOriginal list of numbers:",nums)
print("After removing the duplicate numbers from the said list:")
print(unique_nums(nums))
Sample Output:
Original list of numbers: [1, 2, 3, 2, 3, 4, 5] After removing the duplicate numbers from the said list: [1, 4, 5] Original list of numbers: [1, 2, 3, 2, 4, 5] After removing the duplicate numbers from the said list: [1, 3, 4, 5] Original list of numbers: [1, 2, 3, 4, 5] After removing the duplicate numbers from the said list: [1, 2, 3, 4, 5]
Pictorial Presentation:

Flowchart:

Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program find the indices of all occurrences of a given item in a given list.
Next: Write a Python program to check whether two given circles (given center (x,y) and radius) are intersecting. Return true for intersecting otherwise false.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join