Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Dictionary adds an unexpected list
my expected output is :
But when the code executes the underlined point it adds the key "switchboard" to dic1,eventhough I initialize dic1 only with "delta".

    home= data.keys()
    for k, v in data.iteritems():
	    for i in v:
		    print dic1,k
		    print dic1
		    print dic2
Because of line 2, dic1 and dic2 are the same dict. Any changes you make to one are made to the other. Use this instead:

dic1, dic2 = {}, {}
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Parsing json - dictionary with in dictionary krish216 6 297 Jul-30-2019, 10:01 PM
Last Post: cvsae
  Unexpected Output using classes and inheritance langley 2 154 Jul-04-2019, 09:33 AM
Last Post: langley
  update values in list based on dictionary bunti 3 721 Jun-10-2019, 07:26 AM
Last Post: perfringo
  Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV dn237 19 607 May-29-2019, 02:27 AM
Last Post: heiner55
  Iterate through a list of dictionary and append a new value. erina 1 210 May-16-2019, 09:55 AM
Last Post: perfringo
  Convert List of Dictionary to dictionary of dictionary list in python kk230689 2 290 Apr-27-2019, 03:13 AM
Last Post: perfringo
  syntax error near unexpected token btom529 5 529 Apr-21-2019, 09:03 PM
Last Post: btom529
  Getting an unexpected generator object ? mcgrim 19 639 Mar-29-2019, 11:35 AM
Last Post: gontajones
  unexpected EOF while parsing whatloop 3 879 Mar-09-2019, 06:59 PM
Last Post: whatloop
  Unexpected round behavior pythonCoder 1 249 Feb-19-2019, 02:39 PM
Last Post: marienbad

Forum Jump:

Users browsing this thread: 1 Guest(s)