Answer the question
In order to leave comments, you need to log in
How to remove duplicates from a list with datatype checking?
there is this code
def clean_list(l):
result = []
for item in l:
if item not in result:
result.appent(item)
return result
only it doesn't distinguish float from int it doesn't reach me where to do type checking
Answer the question
In order to leave comments, you need to log in
If I understand the question correctly, then:
def clean_list(a):
out = []
for im in a:
tmp = [im, type(im)]
if not tmp in out:
out.append(tmp)
return [x[0] for x in out]
print(clean_list([1, 1, 2.0, 2, 2.0, 3, 1, 2, 3.0, 3.0, 2.0, 4, 4.0, 3.0]))
[1, 2.0, 2, 3, 3.0, 4, 4.0]
1. What was wrong with set()?
2. ?
def clean_list(l):
result = []
for item in l:
if int(item) not in result:
result.appent(int(item))
return result
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question