Define a Python function remdup(l) that takes a nonempty list of integers l and removes all duplicates in l, keeping only the first occurrence of each number. For instance:
Answers
Answered by
2
def remdup(value):
if (value.length > 0):
temp_set = set(value)
return list(temp_set)
else:
print("Please provide a nonempty list")
listvar = list(2,7,9,6,4,6,8,5)
print(remdup(listvar))
Answered by
0
Answer:
for nptel 3
Explanation:
def remdup(l):
l.reverse()
c1=len(l)
c=0
for a in l:
c=c+1
l2=l[c:c1]
l2.reverse()
for b in l2:
if a==b:
l.reverse()
i=l.index(a)
del l[i]
l.reverse()
l.reverse()
return(l)
Similar questions
English,
5 months ago
Science,
5 months ago
India Languages,
10 months ago
India Languages,
10 months ago
Math,
1 year ago
Social Sciences,
1 year ago