Codepath

Experiment Analysis

Unit 2 Session 1 (Click for link to problem statements)

U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Q: What is the problem asking for?

    • A: The problem asks to return a new dictionary containing only the key-value pairs found exclusively in experiment1 but not in experiment2.
  • Q: What are the inputs?

    • A: Two dictionaries, experiment1 and experiment2.
  • Q: What are the outputs?

    • A: A dictionary containing key-value pairs that are in experiment1 but not in experiment2.
  • Q: Are there any constraints on the dictionaries?

    • A: The dictionaries can have any key-value pairs.

P-lan

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`.

I-mplement

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
Fork me on GitHub