Use random.sampleto select random non-repeating elements:
>>> import random
>>> random.sample(glob.glob('*.jpg'), number_of_images_to_choose)
random.samplereturns an object list.
Side note: there is no need to understand the list if you do not plan to filter the result glob.glob.
source
share