- 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 ??
3 Respuestas
+ 3
Post your attempt first to get help from the community .
+ 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]
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.