title: Iteration through a list derived using set is not as expected in python
body: <p>I am trying to first identify some unique values in a list of values and then reconstruct the original list from the unique values. For example lets say in a directory I have following data sets</p>
  
  <pre><code>a_test_1.txt  a_test_2.txt  a_test_3.txt  b_test_1.txt  b_test_2.txt  b_test_3.txt
  </code></pre>
  
  <p>I would like to uniquely identify a_ and b_ . I think I succeed in this. Following this I would like to use this list which contains a_ and b_ and go back to the original list of files. Here is the code I used</p>
  
  <h2><strong>Attempt 1</strong></h2>
  
  <pre><code>import os, fnmatch
  def find(pattern, path):
      result = []
      for root, dirs, files in os.walk(path):
          for name in files:
              if fnmatch.fnmatch(name, pattern):
                  result.append(os.path.join(root, name))
      return result
  
  
  ids_train=[]
  #base='/data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/'
  base = 'attempt/'
  for path in find('*.txt',base):
          ids_train.append(path)
  ids2=[]
  for idd in ids_train:
          ids2.append(idd.split('test')[0])
  ids2=list(set(ids2))
  # I will do some operations on ids2 here which I am skipping for simplicity
  for idd in ids2:
          print(idd)
  print("now printing resconstructed")
  for idd in ids2:
          for data in find(idd.strip(base)+'*',base):
                  print(data,idd.strip(base)+'*')
  </code></pre>
  
  <h2>Output</h2>
  
  <pre><code>attempt/a_
  attempt/b_
  now printing resconstructed
  attempt/b_test_1.txt b_*
  attempt/b_test_2.txt b_*
  attempt/b_test_3.txt b_*
  </code></pre>
  
  <h2>Attempt 2</h2>
  
  <p>Now I tried absolute path instead of relative</p>
  
  <pre><code>import os, fnmatch
  def find(pattern, path):
      result = []
      for root, dirs, files in os.walk(path):
          for name in files:
              if fnmatch.fnmatch(name, pattern):
                  result.append(os.path.join(root, name))
      return result
  
  
  ids_train=[]
  base='/data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/'
  #base = 'attempt/'
  for path in find('*.txt',base):
          ids_train.append(path)
  ids2=[]
  for idd in ids_train:
          ids2.append(idd.split('test')[0])
  ids2=list(set(ids2))
  # I will do some operations on ids2 here which I am skipping for simplicity
  for idd in ids2:
          print(idd)
  print("now printing resconstructed")
  for idd in ids2:
          for data in find(idd.strip(base)+'*',base):
                  print(data,idd.strip(base)+'*')
  </code></pre>
  
  <h2>Output</h2>
  
  <pre><code>/data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/b_
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/a_
  now printing resconstructed
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/b_test_1.txt b*
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/b_test_2.txt b*
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/b_test_3.txt b*
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/a_test_3.txt *
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/b_test_1.txt *
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/a_test_2.txt *
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/b_test_2.txt *
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/b_test_3.txt *
  /data/data_us4/home/plaquestudy/nhm_processing/plaque_CNNSeg/attempt/a_test_1.txt *
  </code></pre>
  
  <p>In both cases I failed to reconstruct the desired list</p>