Random.sample(list, len(list))

it seems that we cant shuffle items of a directory with random.sample . because we should write : a=random.sample(source_directory, len(source_directory))
after this we need to split data so we write :

        for file in os.scandir(a):

                size=os.path.getsize(file)

                if size == 0 :
   
                     print(f"{file.name} is zero length, so ignoring.")

                     os.remove(file.path)

but it gives eror about the for loop
how we can shuffle items in directory?
]

You are right in pointing out that we can’t shuffle items of a directory. But, this is not what the assignment asks you to do.
Please do this:

  1. List contents of the source directory. See os.listdir
  2. Create a filtered list of files whose size is not 0 bytes.
  3. Shuffle the filtered list of path / file names.

you mean that i have to put random.sample in the loop which filters the size of images?

You have to sample valid images. So, use random.sample outside the loop.