Write a method rem that takes as input a list containing pos

Write a method rem() that takes as input a list containing, possibly, duplicate values and returns a copy of the list and which one copy of every duplicate value removed


10.20

Solution

def rem(list_):
elements = {}
copy_list = []
  
for item in list_:
if item in elements:
elements[item] = elements[item]+1
else:
elements[item] = 1
  
for keys in elements:
for i in range(elements[keys]-1):
copy_list.append(keys)
  
return copy_list

print rem([2,4,2,4,4])
print rem([4,1,2,3])
print rem([4])
print rem([4,4])

OUTPUT:

 Write a method rem() that takes as input a list containing, possibly, duplicate values and returns a copy of the list and which one copy of every duplicate val

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site