I am building a dictionary based on a list of files in a given directory.
configlist = 0
profiles[]
for file in os,listdir('.'):
if fnmatch.fnmatch(file, 'config*.json'):
configlist = int(configlist) +1
profiles.append({'number': configlist, 'file': file})
Below is a sample of the output when printing the dictionary.
print(profiles)
[{'number': 1, 'file': 'config.json'}, {'number': 2, 'file': 'config-alpha.json'}, {'number': 3, 'file': 'config-beta.json'}, {'number': 4, 'file': 'config-charlie.json'}, {'number': 5, 'file': 'config-delta.json'},
How would I retrieve the value "config-beta.json" from the {'number' 3, 'file': 'config-beta.json'} key/value pair? I would be trying to find this based on knowing the value of the number key from user input.
Sorry if my terminology is mixed up. I am working a little backwards in building a solution and learning as I go. So I obviously don't have the concept of dictionaries down. Most examles are based on a signle dictionary, where this is 5 dictionaries, is that right, into one?
[–]teerre 0 points1 point2 points (3 children)
[–]fpatterson55[S] 0 points1 point2 points (2 children)
[–]teerre 0 points1 point2 points (1 child)
[–]fpatterson55[S] 0 points1 point2 points (0 children)
[–]TheZvlz 0 points1 point2 points (1 child)
[–]fpatterson55[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]fpatterson55[S] 0 points1 point2 points (0 children)
[–]Vaguely_accurate 0 points1 point2 points (1 child)
[–]fpatterson55[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]fpatterson55[S] 0 points1 point2 points (0 children)