The difference function is designed to compare two dictionaries, d1 and d2, and return a new dictionary containing items from d1 that are not found in d2. The function allows for a maximum recursion depth determined by the level parameter, where a level of -1 allows for infinite depth. If a key exists in both dictionaries but the values differ, the value from d1 is included in the result as well.
Input/Output Behavior:
Input: The function takes two parameters, d1 and d2, both of which are expected to be dictionaries (or sub-dictionaries). It also takes an optional level parameter, which defaults to -1.
Output: Returns a dictionary containing keys present in d1 but not in d2, or with differing values if they are both present. The recursion will only go as deep as specified by the level.
Edge Cases:
If either d1 or d2 is not a dictionary, the function should return d1 as is.
If both dictionaries are empty, the function should return an empty dictionary.
If both dictionaries are identical, the function should return an empty dictionary as well.
If level is set to 0, the function should return d1 without descending into its sub-dictionaries.
Notes:
The solution should be placed in /app/solution.py.
The function must be importable as: from solution import difference.