Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:adding': 0.07; 'doing?': 0.09; 'line:': 0.09; 'works.': 0.09; 'dict': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'simple.': 0.16; 'subject:Problem': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'code,': 0.22; 'saying': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'refers': 0.24; 'looks': 0.24; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'trivial': 0.31; 'run': 0.32; 'something': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'wrong': 0.37; 'being': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'referred': 0.60; 'here': 0.66; 'as:': 0.81; 'dict.': 0.84; 'subject:Value': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=VomtAoGn c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=aoAcgTy3oA8A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=NZd4OaDlNAPv8kb6Tw8A:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett:2500 Date: Tue, 04 Nov 2014 20:19:32 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Problem adding a Key Value pair References: <32931127-fc4d-4ea5-87eb-f763a4fdf52c@googlegroups.com> In-Reply-To: <32931127-fc4d-4ea5-87eb-f763a4fdf52c@googlegroups.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415132384 news.xs4all.nl 2959 [2001:888:2000:d::a6]:38002 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80231 On 2014-11-04 19:37, Anurag Patibandla wrote: > > I am trying to add a key value pair of ("Priority":"1") to queue1, ("Priority":"2") to queue2, and ("Priority":"3") to queue3. > When I just add ("Priority":"1") to queue1, it works. > But when I run the above code, ("Priority":"3") is being added to all the queues. > This looks trivial and I don't understand why this is happening. Is there something wrong with what I am doing? > > json_split = {} > value = {"Status": "Submitted", "m_Controller": "Python"} > a = range(31) > del a[0] That's better as: a = range(1, 31) > for i in a: > json_split[i] = value Here the key will be whatever 'i' refers to (1..30) and the value will be the dict referred to by 'value'. Try adding the line: print json_split[1] is json_split[2] It'll print out 'True'; it's saying that they are the same dict. You want the values of json_split to be _separate_ dicts. The fix is simple. Just make a copy of the dict for each one: for i in a: json_split[i] = dict(value) [snip]