Comparing a dictionary with a list and making sure the elements match

Hi, I need to be able to match a dictionaries elements with a lists elements using a for loop, I’m not sure how to do this, can anyone help please?


Do you mean if list elements are in a dictionary? Please provide the code that you’ve written so far.

Yes, I need to check that the elements in the list match those of the dictionary, for example:

“fruit”: 1,
“brand”: Granny Smith",
“colour”: “green”,
“quantity”: 4,
“price”: 1
“fruit”: 2
“brand”: “Gala”,
“colour”: “yellow”,
“quantity”: 4,
“price”: 1,
Shop = [Fruit_001_GrannySmith_SecondAisle.jpg],

import os
import json
from pprint import pprint

with open(‘shops.json’) as f:
data = shops.load(f)
shop = {}
for item in data:
shop[item[‘fruit’]] = item

path = r"C:\Users\kjhkhuhuhiuiu"
validation_keys = [“fruit”, “brand”, “colour”, “quantity”, “price”]
for filename in os.listdir(path):
temp_array = filename.split(“_”)
number = temp_array[1]

This is what I’ve got so far, but I need to create a for loop to check there’s no spelling mistakes, elements missing etc etc.

What do the instructions say? Can you provide a link to the lesson?
Also, please format your code using the “</>” above.