Python dictionary program output issue -


I am working on an exercise program. It prints very well but the point is that the last three lines of output are wrong every time I run the program, it generates different outputs, alternatives between keys. I'm not able to find a way to correct it (as written in the program)

  def (main): zip_dictionary = {} zip_dictionary = update_dictionary (zip_dictionary, " CAM "," 1427 ") zip_dictionary = update_dictionary (zip_dictionary," UofM "," 1427 ") zip_dictionary = update_dictionary (zip_dictionary," zit "," 1423-503 ") zip_dictionary = update_dictionary (zip_dictionary," MCOC "," 1423 " ) zip_dictionary = update_dictionary (zip_dictionary, "Nazareth", "1418") zip_dictionary = update_dictionary (zip_dictionary, "OCC", "1420") to zip_dictionary key: range I print (key, zip_dictionary [key]) ( 2): z in print (zip_dictionary.popitem ()) For ip_dictionary value: (print zip_dictionary [value] key) def Update_dictionary (DCT, key, value): DCT [key] = value DCT main ()  

< Div class = "post-text" itemprop = "text">

Use an ordering order, do not print update_dictionary , and key You are restarting on value .

  Import command imports mainly (ordered): zip_dictionary = OrderedDict () zip_dictionary [ "CAM"] = "1427" zip_dictionary [ "UofM"] = "1427" zip_dictionary [ "zit "] =" 1423-503 "zip_dictionary [" MCOC "] =" 1423 "zip_dictionary [" Njhriath "] =" 1418 "zip_dictionary [" OCC "] =" 1420 "print" \ n content dictionary: "Key Print (zip_dictionary.popitem ()) print \ "zip_dictionary: key (zip_dictionary [key]) in print (key, zip_dictition [key]) print" \ ncause item: "range (2): print Replace \ "items for the key: Print Main ()  

Results: Dictionary of materials: ( 'CAM', '1427') ( 'Uofm', '1427') ( 'JIT' 1423-503 ') (' Msiosi ',' 1423 ') (' Nazarene ' ('OCC', '1420') ('OCC', '1420') ('OCC', '1420') ('Nazarene', '1418') Remaining Items: ('CAM', '1427') ('UOFM' , '1427') ('JIT', '1423-503') ('MCOC', '1423')


Comments