python dictionary get by value
Question: So my problem is how to get VALUE by key rather getting a pointer. I have the
following code, and I want to do sth to tempA without changing the value
within dictionary.

    
    
    temp_keys=["a","b","c","d"]
    temp_values=[[1,1],[2,2],[3,3],[4,4]]
    temp=dict(zip(temp_keys,temp_values))
    
    tempA=temp.get('a',temp.copy())
    tempA.append(2)
    print temp
    

output is:

    
    
    {'a': [1, 1, 2], 'b': [2, 2], 'c': [3, 3], 'd': [4, 4]}
    

See the value of key "a" has been changed.  
I want my variable temp unchanged,

    
    
    {'a': [1, 1], 'b': [2, 2], 'c': [3, 3], 'd': [4, 4]}
    


Answer: I believe you are looking for deep copy

    
    
    import copy
    temp_keys=["a","b","c","d"]
    temp_values=[[1,1],[2,2],[3,3],[4,4]]
    temp=dict(zip(temp_keys,temp_values))
    print temp
    temp_copy = copy.deepcopy(temp)
    temp_copy['a'].append(2)
    print temp
    

Your `temp` will remain unchanged:

> {'d': [4, 4], 'b': [2, 2], 'c': [3, 3], 'a': [1, 1]} {'d': [4, 4], 'b': [2,
> 2], 'c': [3, 3], 'a': [1, 1]}

