Advertisement
DrAungWinHtut

duplicate2.py

Aug 14th, 2022
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1.  
  2. # Program : duplicate.py
  3. # Programmer: Dr. Aung Win Htut
  4. # 14-08-2022 0830PM
  5. # version 1.0
  6.  
  7.  
  8. li1 = ['a', 'a', 'b', 'b', 'b', 'a', 'b', 'aa', 'a', 'b', 'c']  # original list
  9. temp = []  # duplicate index storage list
  10. final = []  # after removing duplicate list
  11.  
  12. flag = True  # check in temp list, if not included True else False
  13.  
  14. for i in range(len(li1)):  # first search index i
  15.     for j in range(i+1, len(li1)):  # second compare index i+1
  16.         flag = True
  17.         if temp != []:  # if temp is empty, no checking needed
  18.             for k in temp:  # else check every elements in temp whether already present in temp
  19.                 print(i)
  20.                 print(j)
  21.                 print(k)
  22.                 print()
  23.                 if(k == j):  # already included in temp, then no need to operate that index to compare, abort
  24.                     flag = False
  25.  
  26.         # not included in temp and duplicate then add this index to temp
  27.         if((flag == True) and (li1[i] == li1[j])):
  28.             temp.append(j)
  29.  
  30. print(temp)
  31. temp.sort()
  32. print(temp)
  33.  
  34. # must exclude index stored in temp
  35. for i in range(len(li1)):
  36.     flagOK = True
  37.     for l in temp:
  38.         if i == l: #if this index is included in temp then must omit it
  39.             flagOK = False
  40.  
  41.     if(flagOK == True): #if not included in temp then safe to append to final list
  42.         final.append(li1[i])
  43.  
  44.  
  45. print("final = ")
  46. print(final)
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement