Lists & "pointers"

André Malo auch-ich-m at g-kein-spam.com
Sat Jul 23 17:22:52 EDT 2005


* Kay Schluehr wrote:

> you might initialize self.storedAttr with empty dicts and fill them
> later:
> 
> self.soredAttr = [{}]*10
> for entry in self.storedAttr:
>     entry.update(self.drawAttr)

As a matter of fact, you're doing the same ;-)

In [1]: x = [{}] * 10

In [2]: x[0]['a'] = 1

In [3]: x[1]['b'] = 2

In [4]: x
Out[4]:
[{'a': 1, 'b': 2},
 {'a': 1, 'b': 2},
 {'a': 1, 'b': 2},
 {'a': 1, 'b': 2},
 {'a': 1, 'b': 2},
 {'a': 1, 'b': 2},
 {'a': 1, 'b': 2},
 {'a': 1, 'b': 2},
 {'a': 1, 'b': 2},
 {'a': 1, 'b': 2}]

nd
-- 
"Umfassendes Werk (auch fuer Umsteiger vom Apache 1.3)"
                                          -- aus einer Rezension

<http://pub.perlig.de/books.html#apache2>



More information about the Python-list mailing list