Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Q: What is the problem asking for?
experiment1
but not in experiment2
.Q: What are the inputs?
experiment1
and experiment2
.Q: What are the outputs?
experiment1
but not in experiment2
.Q: Are there any constraints on the dictionaries?
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Iterate through the keys in experiment1
and check if they are not in experiment2
or have different values in experiment2
. Add these key-value pairs to the result dictionary.
1. Initialize an empty dictionary `result`.
2. Iterate through each key in `experiment1`.
- If the key is not in `experiment2`, add the key-value pair to `result`.
- If the key is in `experiment2` but the values are different, add the key-value pair to `result`.
3. Return the dictionary `result`.
def data_difference(experiment1, experiment2):
result = {}
for key in experiment1:
if key not in experiment2:
result[key] = experiment1[key]
elif experiment1[key] != experiment2[key]:
result[key] = experiment1[key]
return result