Static dictionary in python

dict = {}    
def Update_Dictionary(mydict,list,cmdId):    
    mydict['cmdid'] = list
    print mydict    
Update_Dictionary(dict,[1,2,3],1)
Update_Dictionary(dict,[4],2)         

I need the dictionary to be updated not over written. At the end I should have 2 key value pair. Please help me in this.

Answers


instead of

mydict['cmdid'] = list

try

mydict[cmdId] = list

Remove the quotes:

def Update_Dictionary(mydict,list,cmdId):    
    mydict[cmdId] = list
    print mydict  

You are always assigning a new value for the literal string 'cmdid' instead of the parameter cmdId.


Need Your Help

Dropdown submenu disappears in ie8 when page load

css wordpress internet-explorer

Dropdown submenu disappears in ie8 but it works fine in ie9,chrome or firefox.I try it in different way, but its not work. Here is the link

How can I make a JavaScript alert before a page closes?

javascript html alert

I want to write JavaScript code that would, when I close the current HTML page, display an alert message like "Are you sure?"