I tried creating a list of unique elements,which came to be a set of unique elements for each step i performed the for loop.The main goal is the commented statement on the top of the algorithm,that says " # the answer is: [‘c’, ‘a’, ‘t’, ‘d’, ‘o’, ‘g’, ‘r’, ‘b’, ‘i’] ".This is a list of unique elements which I want to achieve.Finally pushing all the elements into unique_list List object.
# the answer is: ['c', 'a', 't', 'd', 'o', 'g', 'r', 'b', 'i']
list_ = ['c','c','c', 'a', 't', 'd', 'o', 'g', 'r', 'a', 'b', 'b', 'i', 't']
#print(len(list_))
unique_list_obj = []
count_list = []
def unique_list(list_obj,start):
#print(len(list_obj))
present = False
for i in range(0,len(list_obj),2):
#print(i)
start += 2
if start < len(list_obj):
#print(i,start)
if list_obj[i] == list_obj[start]:
present = False
print(list_obj[i],list_obj[start])
print('------------------------------------')
else:
present = True
print(list_obj[i],list_obj[start])
return unique_list_obj
print(unique_list(list_,1))
Unique elements are missing and some repeated elements are still present.Try modifying this algorithm.