One easy way would be to use glob or os to get all *.jpg files.
Once you have all image paths, you could split them simply by using a condition and finally copy them to the destination folder. Here is some pseudo code:
image_paths = glob.glob('./dogsandcats/train/*.jpg')
dog_paths = []
cat_paths = []
for p in image_paths:
    if 'dog' in p:
        dog_paths.append(p)
    elif 'cat' in p:
        cat_paths.append(p)
    else:
        print('Unknown image: {}'.format(p))

# Split paths to train/val
nb_dogs = len(dog_paths)
dog_paths_train = dog_paths[:int(nb_dogs*0.8)]
dog_paths_val = dog_paths[int(nb_dogs*0.8):]
# same for cat

for p in dog_paths_train:
    shutil.copy2(p, './dogsandcats/train/dog/')
# same for val and cat