title: How to sort image files into two folders based on filename from a list in Python?
body: <p>I have a folder with images of dogs, named dogID-X.jpg where X is the number of the picture that belongs to one dogID, e.g. 0a08e-1.jpg, 0a08e-2.jpg, 0a08e-3.jpg means there are three images that belong to the same dog.
  How do I sort these images into two subfolders based on two lists that have only the dogID [0a08e, 4a45t, ...] i.e. all images with IDs from one list should go to one folder, and all images from another list should go into the other folder. Thanks! The list looks like this: <code>list(y_labels) = ['86e1089a3',
   '6296e909a',
   '5842f1ff5',
   '850a43f90',
   'd24c30b4b',
   '1caa6fcdb', ...]</code></p>
  
  <pre><code>for image in list(y_labels):
                folder = y_labels.loc[image, 'PetID']
                old = './train_images/{}'.format(image)
                new = '//train_images_new/{}/{}'.format(folder, image)
    try:
      os.rename(old, new)
    except:
      print('{} - {}'.format(image,folder))
  </code></pre>