• Test window doesn't mirror what I returned

 

I would like to give some feedback about ...

From: http://www.checkio.org/mission/flatten-dict/solve/

HTTP_USER_AGENT:

Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0

This is what I see in the test 4/4 window:

Your result: {"zone":"","additional/place/zone":"1","job":"scout","additional/place/cell":"2","name/first":"One","name/last":"Drone"}

However, this is what I get when I print the variable 'result' before I actually return it:

{'additional/place/zone': '1', 'job': 'scout', 'additional/place/cell': '2', 'name/first': 'One', 'name/last': 'Drone', 'recent': ''}

Why are they different? It seems to me that 'result' is correct but it changes when it is returned. Or am I missing something?

Here is my code:

def flatten(dictionary):
stack = [((), dictionary)]
result = {}
while stack:
    path, current = stack.pop()
    if not current.items():
        result[k] = ""
    for k, v in current.items():
        if isinstance(v, dict):
            stack.append((path + (k,), v))
        else:
            result["/".join((path + (k,)))] = v
print result
return result

Thanks, Metallidog