title: Python script to remove unique elements from a list and print the list with repeated elements in proper order
body: <p>I have written a script to remove all unique elements from a list and print the list with only repeated elements:</p>
  
  <p>Below are some examples how the output list for an input list should be</p>
  
  <pre><code>Input list1:
  1,2,1,1,3,5,3,4,3,1,6,7,8,5
  
  Output List1:
  1,1,1,3,5,3,3,1,5
  
  Input list2:
  1,2,1,1,3,3,4,3,1,6,5
  
  Output List2:
  1,1,1,3,3,3,1
  
  #! /bin/python
  
  def remove_unique(*n):
      dict1={}
      list1=[]
      for i in range(len(n)):
          for j in range(i+1,len(n)):
              if n[i] == n[j]:
                 dict1[j]=n[j]
                 dict1[i]=n[i]
      for x in range(len(n)):
          if x in dict1.keys():
             list1.append(dict1[x])
      return list1
  
  lst1=remove_unique(1,2,1,1,3,5,3,4,3,1,6,7,8,5)
  for n in lst1:
      print(n, end=" ")
  </code></pre>
  
  <p>The script above works exactly as expected when tested with few smaller lists. However I want some ideas on how to optimize the script (both time and space complexities considered) for input lists with bigger lengths ( 50000 &lt;=len(list) &lt;= 50M )</p>