python - How to get numbers from filenames? -


i have many files in directory according key:

pic001.jpg pic002.jpg pic012.jpg [...] ico001.jpg ico002.jpg ico012.jpg [...] 

and want list files , create structure this:

for r,d,f in os.walk(directory):     file in f:         if file.startswith("pic"):             pic = file             ico = ???             images_list.append({                 'big': directory + '/' + pic,                 'thumb': directory + '/' + ico,             }) 

how "pic" file , "ico" assigned him (only if ico exist)?

the simplest answer seems be:

ico = 'ico' + file[3:] 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -