I have two supplied bits of information: A dictionary of transactions and a list of the unique items in the transactions.
transactions = {
"T1": ["A", "B", "C", "E"],
"T2": ["A", "D", "E"],
"T3": ["B", "C", "E"],
"T4": ["B", "C", "D", "E"],
"T5": ["B", "D", "E"]
}
items = ["A", "B", "C", "D", "E"]
What I need to do is find the number of occurrences of these items in the transactions. I created a dictionary that has keys representing the unique items and the value for each key initialized to 0, but I am unsure of how to update these values to represent the number of occurrences in the transactions.
occurr = dict()
for x in items:
occurr[x] = 0
This is my occurrences dictionary which yields the output:
{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
The final dictionary should look like:
{'A': 2, 'B':4, 'C': 3, 'D': 3, 'E': 5}
as 'A' occurs 2 times in the transactions, 'B' occurs 4 times, etc.