We define a nested mapping as a data structure where each element is either:
Solving this problem with a recursive function is fairly easy. Try to do it without using recursion.
- a value. For the sake of simplicity, we'll say a string.
- a nested mapping.
data = {
a: '1',
b: '2',
c: {
d: '3',
e: { f: '4' },
g: { h: '5' },
i: '6'
},
j: '7'
};
The goal of this exercise is to write a function that takes a nested mapping, replacing every value (string) with the word "replaced". Note that you cannot make any assumption about the depth of the nesting, the following being another example of a valid nested mapping:deeper_mapping = {
a: {
b: {
c: {
d: {
e: {
f: '1'
}}}}}}
ChallengeSolving this problem with a recursive function is fairly easy. Try to do it without using recursion.