- 1

write a function in python to remove duplicates

write a function in python to remove duplicates from a list. number = [23,45,67,78,'Hello',34.34,34j,'Python',34,45.6,'ML',78,'Hello',34.34,34j] Answer : duplicate =[23,45,67,78,'Hello',34.34,34j,'Python',34,45.6,'ML',78,'Hello',34.34,34j] print(list(set(duplicate))) O/p: ['Hello', 34.34, 67, 34, 34j, 'Python', 45, 78, 45.6, 'ML', 23] Is it right?? How do I do it without inbuilt function set ??

5th Feb 2021, 5:26 AM
rajul
4 Antworten
+ 3
Post your attempt first to get help from the community .
5th Feb 2021, 5:35 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 2
duplicate =[23,45,67,78,'Hello',34.34,34j,'Python',34,45.6,'ML',78,'Hello',34.34,34j] print(list(set(duplicate))) Op:['Hello', 34.34, 67, 34, 34j, 'Python', 45, 78, 45.6, 'ML', 23]
5th Feb 2021, 5:41 AM
rajul
0
number = [1, 2,2,3,4,5] num = set(number) number=list(num) # as we know python set doesn't allow duplicate elements in it so a simple type casting is the answer.
5th Feb 2021, 1:30 PM
Yogesh Singh
Yogesh Singh - avatar