class warehouse:
    def __init__(self):
        self.A={}
        self.B={}   
        self.racks={'A':self.initialize(self.A),'B':self.initialize(self.B)}        
    def initialize(self,rack):
        shelf = dict([  (items,0) for items in range(1,6)  ])
        for x in range(3):
            rack[x+1]=shelf 
        return rack 
    def store(self,_id,owner_id,colour,weigth):
        import pdb;pdb.set_trace()          
        empty_position=self.empty_positions(self.store.__name__)[0]     
        self.racks[empty_position[0]][empty_position[1]][empty_position[2]]=   {'id':_id,'owner':owner_id,'colour':colour,'weigth':weigth}          
        print self.racks
    def empty_positions(self,name):
        store_list=[]
        for rack,shelfs in self.racks.iteritems():
            for shelf_number,shelf_objects in shelfs.iteritems():
                    store_list.append([rack,shelf_number])
                    for position,value in shelf_objects.iteritems():
                        if 0==value:
                            store_list.append([rack,shelf_number,position])
        return store_list
obj=warehouse()
val=obj.store(2,34,4,44)                
It is a class warehouse I want to create a dictionary which I did by the calling the init methods of the class.Now I want to store some values into the nested dictionary using same instance of class warehouse.When I call the obj.store(2,34,4,44).It updates the dictionary and gimme the result.
{'A': {1: {1: {'colour': 4, 'id': 2, 'owner': 34, 'weigth': 44},
           2: 0,
           3: 0,
           4: 0,
           5: 0},
       2: {1: {'colour': 4, 'id': 2, 'owner': 34, 'weigth': 44},
           2: 0,
           3: 0,
           4: 0,
           5: 0},
       3: {1: {'colour': 4, 'id': 2, 'owner': 34, 'weigth': 44},
           2: 0,
           3: 0,
           4: 0,
           5: 0}},
'B': {1: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
      2: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
      3: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
     }
 }
But I was expecting :
{'A': {1: {1: {'colour': 4, 'id': 2, 'owner': 34, 'weigth': 44},
           2: 0,
           3: 0,
           4: 0,
           5: 0},
       2: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
       3: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}},
 'B': {1: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
       2: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
       3: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
      }
 }
It sets the value in all the other nested dictionary of key 'A' and 1 I try to put PDB and debuge it, but it is showing the same result. But If I do this operation in teminal then I get the result what I was expecting.
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d={'A': {1: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, 2: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, 3: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}}, 'B': {1: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, 2: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, 3: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}}}
>>> d['A'][1][1]={"some_key":"some_value",}
>>> d
{'A': {1: {1: {'some_key': 'some_value'}, 2: 0, 3: 0, 4: 0, 5: 0}, 2: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, 3: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}}, 'B': {1: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, 2: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, 3: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}}}
I dont know maybe I am missing something, or there is something wrong that I am not able to catch up.I am using python 2.6.6 and tried this is 2.7.1 as well .
 
     
     
    