Reputation: 119
I'm a little stuck with a function I'm writing. Let's say we have a dictionary and a list as below:
dict = {".txt": 10, ".docx": 100"}
files = ["file1.txt", "file2.txt", "file3.docx"]
Let's also say that each file in the list has a certain age, file1_age= 9, file2_age = 13, file3_age = 87
. i.e. they were created 9, 13, and 87 minutes ago respectively.
I'm trying to connect the files in the list with their respective file format in the dictionary. I then want to say if age of file > number in dictionary: do this
It's essentially saying, leave the files as they are until they are a certain age and then do this thing with the files. Some pseudo code below.
for file in files:
if file.endswith(dict.keys()):
if file_age > dic.values():
do this
Any help on how to do this would be much appreciated!
Upvotes: 0
Views: 35
Reputation: 187
You can do
for file in files:
ending = "." + file.split(".")[-1]
if ending in dict:
if file_age > dict[ending]:
#do this
Upvotes: 1