0

I want to remove duplicates from a list by only using for and if else statements, Without using set, enumerate functions, fromkeys and without using new empty array/list. So in the given list, I wish to keep an item only if it appears one time, if it occurs to second time, I wish to delete the second appearance, third appearance

a = ['aa', 'bb', 'cc', 'aa', 'dd', 'ee', 'aa', 'cc', 'ff']

So here I wish to remove 'aa' on the 3rd index and 6th index and 'cc' on 7th index while keeping the rest list as it is.

Kunal
  • 1
  • In this, I was trying to get elements with len >= 2 ---- abc = "asd dwasfd ersgf va s fas DAS AS SDG sd fg sdfg asd gsdgf" ---- abc = abc.split() ---- #print(abc) ---- for i in range(len(abc)): ------ if len(abc[i])<=2: ----- k = abc[i] ---- #abc.remove(k) ---- abc.append(k) ------ #print(abc) ---- for j in abc: ----- if len(j)>2: ----- abc.remove(j) ---- #if count ---- #if len(abc[i])<=2: ----- #abc.pop() ---- #abc.append(abc[i]) ----- #else: ----- #abc.remove(abc[0]) ----- #del abc[abc.index(i)] ------ print(abc) – Kunal Jun 02 '22 at 21:54
  • and I have been able to print same elements twice and was trying to use any if else or loop within the code to remove the item when it appears twice – Kunal Jun 02 '22 at 21:54

0 Answers0