I have a list of dicts, which contain filenames and modification dates in the following format:
fileList = [{"fileName": "file1.txt", "fileMod": "0000048723"},
{"fileName": "file2.txt", "fileMod": "0000098573"}]
I need to query if a fileName
exists in the dictionary and if so return the fileMod value for that entry.
Using a list comprehension:
fileMod = [item['fileMod'] for item in fileList if item['fileName'] == filename]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With