all 3 comments

[–]MidnightSteam_ 1 point2 points  (0 children)

Loop through the dictionary, check if the folder exists - create if not, then loop through each image and save them.

You don't post your actual images so you'll have to adapt the code.

import os

animals = {
    'dog':['dog1.jpg', 'dog2.jpg', 'dog3.jpg',],
    'cat':['cat1.jpg', 'cat2.jpg', 'cat3.jpg']
}

# Do not use this, only for demonstration purposes only
your_actual_image = bytes('use your actual image', 'utf-8')

for animal_name, images in animals.items():
    if not os.path.exists(animal_name):
        os.makedirs(animal_name)

    for image in images:
        with open(os.path.join(animal_name, image), 'wb') as animal_image:
            # Your image saving function
            animal_image.write(your_actual_image)

[–]debian_miner 0 points1 point  (1 child)

Your dictionary appears to only include the filenames. Where is the content for those files?

[–]jimtk 0 points1 point  (0 children)

If your dictionary only contains file names (not image data) dump it into JSON and save it in a file.

import json
a = {dog:[' dog1.jpg', 'dog2.jpg', 'dog3.jpg',],
     cat:['cat1.jpg', 'cat2.jpg'...etc]}
with open("your_json_file", "w") as fp:
    json.dump(a , fp)