Re: Dictionary of lists strange behaviour

2010-11-09 Thread John Posner
On 11/9/2010 1:43 PM, Terry Reedy wrote: ... List *is* useful as an initializer for collecitons.defaultdicts. And it was useful when several members of this forum helped me to develop a prime-number generator. See http://www.mail-archive.com/python-list@python.org/msg288128.html. (I meant t

Re: Dictionary of lists strange behaviour

2010-11-09 Thread Terry Reedy
On 11/9/2010 12:19 PM, Ciccio wrote: Il 09/11/2010 16:47, Terry Reedy ha scritto: On 11/9/2010 9:14 AM, Ciccio wrote: Hi all, hope you can help me understanding why the following happens: In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} In [214]: rg = dict.fromkeys(g.keys(),[]) If you rewr

Re: Dictionary of lists strange behaviour

2010-11-09 Thread Ciccio
Thank you all, this was timely and helpful. francesco -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary of lists strange behaviour

2010-11-09 Thread Ciccio
Il 09/11/2010 16:47, Terry Reedy ha scritto: On 11/9/2010 9:14 AM, Ciccio wrote: Hi all, hope you can help me understanding why the following happens: In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} In [214]: rg = dict.fromkeys(g.keys(),[]) If you rewrite this as bl = [] rg = dict.fromkey

Re: Dictionary of lists strange behaviour

2010-11-09 Thread Terry Reedy
On 11/9/2010 9:14 AM, Ciccio wrote: Hi all, hope you can help me understanding why the following happens: In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} In [214]: rg = dict.fromkeys(g.keys(),[]) If you rewrite this as bl = [] rg = dict.fromkeys(g.keys(),bl) is the answer any more obvious

Re: Dictionary of lists strange behaviour

2010-11-09 Thread Jean-Michel Pichavant
Ciccio wrote: Hi all, hope you can help me understanding why the following happens: In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} In [214]: rg = dict.fromkeys(g.keys(),[]) In [215]: rg Out[215]: {'a': [], 'b': []} In [216]: rg['a'].append('x') In [217]: rg Out[217]: {'a': ['x'], 'b': ['x']}

Dictionary of lists strange behaviour

2010-11-09 Thread Ciccio
Hi all, hope you can help me understanding why the following happens: In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} In [214]: rg = dict.fromkeys(g.keys(),[]) In [215]: rg Out[215]: {'a': [], 'b': []} In [216]: rg['a'].append('x') In [217]: rg Out[217]: {'a': ['x'], 'b': ['x']} What I meant

Re: Dictionary of lists strange behaviour

2010-11-09 Thread Matteo Landi
On Tue, Nov 9, 2010 at 3:14 PM, Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) The argument you pass which is used to fill the values of the new dict, is cr

Re: Dictionary of lists strange behaviour

2010-11-09 Thread Dave Angel
On 2:59 PM, Ciccio wrote: Hi all, hope you can help me understanding why the following happens: In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} In [214]: rg = dict.fromkeys(g.keys(),[]) In [215]: rg Out[215]: {'a': [], 'b': []} In [216]: rg['a'].append('x') In [217]: rg Out[217]: {'a': ['x'