So I have 20 images and I want to put them to a list. But I only know how to do it by appending them one by one which wastes a lot of space. I did try for loop, but I do not know how to make it work.
This is what I want to do, but by using a loop:
list = []
list.append(image1)
list.append(image2)
...
list.append(image20)
What I have tried:
for i in range 20
a = str(i)
list.append(image.join(a))
"image is not defined" is the obvious error I get and I understand what is causing it. The "image" is not defined and I am typing it acting as it should be a variable. Is it somehow possible to change the variable "image" into a string, add str(i) onto it, and then change it back to a variable that includes the number? After which I could input it to the append function.
>Solution :
You can simply do that using glob by filtering image extensions from folder itself.
import glob
img_list = []
for img in glob.glob("Path/to/dir/*.jpg"): #If extension of image is .jpg
img_list.append(img)