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:
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
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":"
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"
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:
>
...
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
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)
...
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
>
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
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
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
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
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
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
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
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
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
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
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
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
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
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 !=
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 =
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
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
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
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
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
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
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
30 matches
Mail list logo