Python Program to Remove Duplicate Elements from a List
ฝัง
- เผยแพร่เมื่อ 16 ก.ย. 2024
- In this tutorial you will learn to write a Python Program to Remove Duplicate Elements from a List.
The function that we create here will take a list which as duplicate elements as a parameter and it will return a list without any duplicates.
our Social Media Pages
/ exampleprogram
/ exampleprogram
/ example_program
Our Website
www.ExamplePro...
#ExampleProgram
Thank you. I appreciate your Support for the Community.
❤️
Thanks sire u helped me solve my assignment 🇳🇬💗💗
Most welcome 😊
You made your code so complex you could just convert the list to sets and all duplicates would be gone
excellent bro
To be fair: I am a beginner and I new about the x2 = list(set(x)) method but I thought I needed to figure out problem solving shit... not thinking once about the possibility of a "not in" statement... so I came here and was enlightened... only to forget it in two days haha.
Doing shit the hard way can be very helpful to learn the basics I guess.
This is exactly what I did. But you will mess up the order. So you have to sort according to the list index.
Yeah
Thanks sire u helped me a lot😘😘😘
Most welcome 😊
YOU SAVED MY LIFE!!!!!!!
Pleasure
thank you, dawg. appreciate ya
No problem
Can we count the duplicate numbers In a list without using count built-in function?
I want an output like...
(Number, repeated x times)
thank you so much it solved my assignment
You are most welcome
for loop would be performance killer if we have a big list...
list comprehension will come in handy in this case
Thank you very much>>>...
You are welcome!
i swear i love u bro
thank you :)
This is really helpful
Glad this helps you :)
Tq Sir
Welcome
Bro u put that duplicate list into set datatype and you again convert the set to the list data type and print the list like this
List1=[ 1,5,6,4,2,3,3,3]
Set1=set(list1)
List1= list(set1)
Print(list1)
Yes..
Friend i have another doubt in .py
If we want to find index of second occurrence of a number in list what we do.. ans need urgent
Nice work
Thanks
Use this rather maybe if you wanna reduce lines of code:
# Function
remove_duplicates = lambda input_list:list(dict({key:0 for key in input_list}))
# Example/Usage
my_list = [...]
my_list = remove_duplicates(my_list)
Please correct me if I am wrong. Why complicating things by defining function. Why not this following simple code:
data=[10, 20, 30, 30, 40, 50, 50, 60, 70]
noduplist=[]
for element in data:
if element not in noduplist:
noduplist.append(element)
print(noduplist)
#output: [10, 20, 30, 40, 50, 60, 70]
totally agree
@Prashant Rai Ok. Thank you.
good one bro!
by defining function we can , use it any no of time with any no of duplicate list , that's what functions are use for...
print(list(set(data))) try this
Thanks
Welcome
Awsm❤️
thank you
Thank you
You're welcome
I am trying to print also the noduplist by the console tells me that it is not defined. What should I do ??
when I heard an Indian accent I knew, I'd learn something today.
👍
We can convert the list into set to remove duplicates
thanks you are amazing 💖💖💖💖💖💖💖💖
It might be a REAL GOOD IDEA to post the code
thanks for the suggestion.
i will try to implement that :)
nice
Thanks
This program question is asked in every interview
oh :)
Sir pls.. say sir
Noduplist is a empty list
But how we check if the element present in noduplist or not...
See what happens is we iterate over the new list and if for example '0' is there in list , program will not execute. Therefore 'not in' is used
❤
thanks
You can just convert it to a set and convert it back to a list.
Can't you sort it, loop through the array comparing it to the last element and if so delete that that element/append it if not, to a noduplist. Then it sorts in nlog(n) time and runs in n time. This will run in worst case (n/2)^2. which is worse after 8 elements.
For elements in duplist likhna jaruri hai kya ?
👍👍👍
Thank you :)
It's not working in my system. Error says function object not iterable
It would be great if you could show how to do it withouth the "not in" method. That is what I am trying to do. I am trying to loop through "unique" and if "i" is not equal to "j" then I append i to unique. However, I am doing something wrong sintaxis wise.
but how to remove duplicate with that number for example numbers=[2,2,4,4,6,8,8,9] it will be unique =[6,9] . how to solve that problem?
Please tell me how to remove alternative eliminats in a list
Nice video but...?
How do you delete the '+' in the list below?
My_list=[+1222..., +1838..., 1737...]
Sir ye har value ke liye kam nhi krega.
While loop se krye ek baar
data = [10,20,20,30,40,50,50]
def remove_duplicate(data, i):
if i >= len(data):
return data
if isinstance(data[i], int):
if data[i] == data[i+1]:
data.pop(i)
return remove_duplicate(data, i+1)
print(remove_duplicate(data, 0))
Is this even efficient?
Sir what is the output for 1-2,2-3,3-4,4-5
Your explanation is not to the point.
Can't understand what are saying.
This program is wrong