Copmlex structures....

Neal Norwitz neal at metaslash.com
Fri Mar 22 17:18:19 EST 2002


"Dmitry S. Makovey" wrote:
> 
> Hi. The problem itself is - I want to use complex structures like described
> below, but i want it another way....
> 
> 01. >>> f={}
> 02. >>> f['name']='dimon'
> 03. >>> f['age']=20
> 04. >>> a=[]
> 05. >>> a.append(f)
> 06. >>> print a
> 07. [{'age': 20, 'name': 'dimon'}]
> 08. >>> f['age']=22
> 09. >>> print a
> 10. [{'age': 22, 'name': 'dimon'}]
> 
> I don't like result in the last like I've expected to have [{'age': 20,
> 'name': 'dimon'}], how could i do this?
> 
> I know that it must be as simple as using something like b[:], but what?

	f.copy()

>>> f={}
>>> f['name'] = 'dimon'
>>> f['age']=20
>>> a=[]
>>> a.append(f.copy())
>>> print a
[{'age': 20, 'name': 'dimon'}]
>>> f['age']=22
>>> print a
[{'age': 20, 'name': 'dimon'}]

Neal



More information about the Python-list mailing list