[issue45437] Assignment to a list of dictionary wrong

2021-10-11 Thread Zachary Ware
Zachary Ware added the comment: See https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list Not quite the same example, but the underlying reason for what you're seeing is the same: each of the `dict` objects in `[{}] * 4` is actually the *same* dict object:

[issue45437] Assignment to a list of dictionary wrong

2021-10-11 Thread Xin Sheng Zhou
New submission from Xin Sheng Zhou : >>> details = [{}]*4 >>> details [{}, {}, {}, {}] >>> details[1]['A']=5 >>> details [{'A': 5}, {'A': 5}, {'A': 5}, {'A': 5}] >>> -- messages: 403679 nosy: xinshengzhou priority: normal severity: no

Re: how to remove duplicates dict from the list of dictionary based on one of the elements is duplicate in list of dict

2019-11-16 Thread Cameron Simpson
On 17Nov2019 12:26, Iranna Mathapati wrote: How to remove duplicates dict from the list of dictionary based on one of the duplicate elements in the dictionary, l = [{"component":"software", "version":"1.2" }, {"component":"

how to remove duplicates dict from the list of dictionary based on one of the elements is duplicate in list of dict

2019-11-16 Thread Iranna Mathapati
Hi, How to remove duplicates dict from the list of dictionary based on one of the duplicate elements in the dictionary, l = [{"component":"software", "version":"1.2" }, {"component":"hardware", "version":"2.2"

Re: list or dictionary

2016-09-21 Thread Ganesh Pal
Thanks , and it has to be re.match() On Thu, Sep 22, 2016 at 12:18 AM, MRAB wrote: > On 2016-09-21 19:35, Ganesh Pal wrote: > >> Thanks Steve for the clues , quickly tried out # Version 1 doesn't seen >> to work. >> >> >> for line in hostname: > ...

Re: list or dictionary

2016-09-21 Thread MRAB
On 2016-09-21 19:35, Ganesh Pal wrote: Thanks Steve for the clues , quickly tried out # Version 1 doesn't seen to work. for line in hostname: ... regex = r'(.*) is array with id {}'.format(devid) ... mo = re.search(regex, line) ... print line, regex, mo ... if mo is not

Re: list or dictionary

2016-09-21 Thread Ganesh Pal
Thanks Steve for the clues , quickly tried out # Version 1 doesn't seen to work. >>> for line in hostname: ... regex = r'(.*) is array with id {}'.format(devid) ... mo = re.search(regex, line) ... print line, regex, mo ... if mo is not None: ... print mo.group(1) ...

Re: list or dictionary

2016-09-20 Thread Steve D'Aprano
On Wed, 21 Sep 2016 04:04 am, Ganesh Pal wrote: > I am on python 2.7 and Linux > > I have the stdout in the below form , I need to write a function to get > hostname for the given id. > > > Example: > stdout > 'hostname-1 is array with id 1\nhostname-2 is array with id 2\nhostname-3 >

Re: list or dictionary

2016-09-20 Thread Chris Angelico
On Wed, Sep 21, 2016 at 4:04 AM, Ganesh Pal wrote: > 1. store it in list and grep for id and return > 2. store it in dict as key and value i.e hostname = { 'hostname1': 1} and > return key > 3. any other simple options. 4. Store it in dict, but the other way around. The key

Re: list or dictionary

2016-09-20 Thread Lawrence D’Oliveiro
On Wednesday, September 21, 2016 at 6:05:41 AM UTC+12, Ganesh Pal wrote: > I am on python 2.7 ... Why? -- https://mail.python.org/mailman/listinfo/python-list

list or dictionary

2016-09-20 Thread Ganesh Pal
I am on python 2.7 and Linux I have the stdout in the below form , I need to write a function to get hostname for the given id. Example: >>> stdout 'hostname-1 is array with id 1\nhostname-2 is array with id 2\nhostname-3 is array with id 3\n' def get_hostname(id) return id what's a

Python 2.4 and list of dictionary issues

2010-02-07 Thread Chris Stevens
Hi all, I'm a python newbie so please excuse me if I am missing something simple here. I am writing a script which requires a list of dictionaries (originally a dictionary of dictionaries, but I changed it to a list to try and overcome the below problem). Now my understanding is that you create

Re: Python 2.4 and list of dictionary issues

2010-02-07 Thread Chris Rebert
On Sun, Feb 7, 2010 at 9:08 PM, Chris Stevens cjstev...@gmail.com wrote: Hi all, I'm a python newbie so please excuse me if I am missing something simple here. I am writing a script which requires a list of dictionaries (originally a dictionary of dictionaries, but I changed it to a list to

How to manipulate list of dictionary

2008-08-26 Thread ajak_yahoo
Hi, Need some help, I have a list of dictionary as below, table = [{Part #:Washer,Po #:AE00128,qty:100}, {Part #:Brake Pad,Po #:AE00154,qty:150}, {Part #:Mesh,Po #:AE00025,qty:320}, {Part #:Mouse,Po #:AE00207,qty:120}, {Part #:Insulator,Po #:AE0013,qty:190

Re: How to manipulate list of dictionary

2008-08-26 Thread Simon Brunning
2008/8/26 ajak_yahoo [EMAIL PROTECTED]: Need some help, I have a list of dictionary as below, table = [{Part #:Washer,Po #:AE00128,qty:100}, {Part #:Brake Pad,Po #:AE00154,qty:150}, {Part #:Mesh,Po #:AE00025,qty:320}, {Part #:Mouse,Po #:AE00207,qty:120

Re: How to manipulate list of dictionary

2008-08-26 Thread Bruno Desthuilliers
Simon Brunning a écrit : 2008/8/26 ajak_yahoo [EMAIL PROTECTED]: Need some help, I have a list of dictionary as below, table = [{Part #:Washer,Po #:AE00128,qty:100}, {Part #:Brake Pad,Po #:AE00154,qty:150}, {Part #:Mesh,Po #:AE00025,qty:320}, {Part #:Mouse,Po

modifying values of List or Dictionary when iterating on them

2007-05-24 Thread aspineux
Hello I just want to update the data inside List or Dictionary without adding or deleting object. is this correct ? l=[1, 2, 3] for i, v in enumerate(l): l[i]=v+1 d=dict(a=1, b=2, c=3) for k, v in d.iteritems(): d[k]=d[k]+1 Both works, but : are they correct ? are they optimum

Re: modifying values of List or Dictionary when iterating on them

2007-05-24 Thread Christopher Anderson
d=dict(a=1, b=2, c=3) for k, v in d.iteritems(): d[k]=d[k]+1 You might as well do: d[k] = v + 1, like for the list. -- http://mail.python.org/mailman/listinfo/python-list

Re: modifying values of List or Dictionary when iterating on them

2007-05-24 Thread aspineux
On 24 mai, 19:21, Christopher Anderson [EMAIL PROTECTED] wrote: d=dict(a=1, b=2, c=3) for k, v in d.iteritems(): d[k]=d[k]+1 You might as well do: d[k] = v + 1, like for the list. ops, yes it was a typo -- http://mail.python.org/mailman/listinfo/python-list

querying dictionary / list of dictionary like SQL

2007-05-22 Thread [EMAIL PROTECTED]
Hi Is there a module /add on in python that will let me query a dictionary [ or a list of dictionary] exactly like an SQL query? For ex: a=[{'id':1, 'name':'mark'}, {'id':2,'name': 'richard'}] select * from a where id =1 should give me the a[0] or something similar to this. thanks -- http

RE: list of dictionary in embedded Python

2007-03-13 Thread ZiZi Zhao
You are right! I added Py_INCREF(pDict); right behind pDict = PyDict_New(); it seems to work correctly. thanks, zz -Original Message- From: [EMAIL PROTECTED] on behalf of Gabriel Genellina Sent: Thu 3/8/2007 7:15 PM To: python-list@python.org Subject: Re: list of dictionary

list of dictionary in embedded Python

2007-03-08 Thread ZiZi Zhao
I tried to build a list of dictionaries using embedded Python2.5 in the following way to append dictionaries to a list. Py_Object *pList = PyList_New(0); for (i=0; iMAXSIZE; i++) { Py_Object *pDict = PyDict_New(); // // build this dictionary of keys values // if (pDict !=

Re: list of dictionary in embedded Python

2007-03-08 Thread Gabriel Genellina
En Thu, 08 Mar 2007 22:26:59 -0300, ZiZi Zhao [EMAIL PROTECTED] escribió: I tried to build a list of dictionaries using embedded Python2.5 in the following way to append dictionaries to a list. Py_Object *pList = PyList_New(0); for (i=0; iMAXSIZE; i++) { Py_Object *pDict =

Recursive tree list from dictionary

2006-01-14 Thread David Pratt
Hi. I am wanting to create a tree list result structure from a dictionary to categorize results. The dictionary contains elements that identify its parent. The levels of categorization is not fixed, so there is a need for the code to be recursive to drill down to the lowest level. I have

Re: Recursive tree list from dictionary

2006-01-14 Thread Max Erickson
David Pratt [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Hi. I am wanting to create a tree list result structure from a dictionary to categorize results. The dictionary contains elements that identify its parent. The levels of categorization is not fixed, so there is a need for the

Re: Recursive tree list from dictionary

2006-01-14 Thread bearophileHUGS
This isn't much tested, so don't trust it much, and I hope it's not overkill. You can find Graph here: http://sourceforge.net/projects/pynetwork/ With this you can plot the tree, if you want: g.springCoords(); g.plot2d() Bear hugs, bearophile def scan(g, parent): subs = [scan(g, sub) for

Re: Recursive tree list from dictionary

2006-01-14 Thread Alan Franzoni
Il Sat, 14 Jan 2006 13:52:43 -0400, David Pratt ha scritto: source_list =[ I don't understand what you mean by saying that 'levels of categorization is not fixed', are there more than two keys in any dictionary? Basically, thus, you have a list of dictionaries and you want to get a list of

Re: Recursive tree list from dictionary

2006-01-14 Thread David Pratt
Hi Allan, Max, and bearophile Many thanks for your replies to this. The number of levels can be deeper than two for creating child, sibling relationships. This can lead to futher nesting as shown in my sample result list (the result I am attempting to acheive) which is reason that I believe

Re: Recursive tree list from dictionary

2006-01-14 Thread Bengt Richter
On Sat, 14 Jan 2006 16:46:29 -0400, David Pratt [EMAIL PROTECTED] wrote: Hi Allan, Max, and bearophile Many thanks for your replies to this. The number of levels can be deeper than two for creating child, sibling relationships. This can lead to futher nesting as shown in my sample result list

Re: Recursive tree list from dictionary

2006-01-14 Thread David Pratt
Hi Bengt! I have been banging my head on this one all day! This is brilliant (and recursive through each level which is exactly what I was trying to work out)! Only part I needed to modify is else: return title to else: return [title] I tell you, you've made my day! I was getting a bit