Y.A.S.D.

Python

うーん,恥ずかしいとこでハマってた。代入は copy ではなく bind だったよな。

[~]$ python
	:
>>> t = { 0:'zero', 1:'one' }
>>> tt = {}          
>>> tt['a'] = t
>>> tt['b'] = t
>>> tt['a'][2] = 'two'
>>> tt
{'b': {2: 'two', 1: 'one', 0: 'zero'}, 'a': {2: 'two', 1: 'one', 0: 'zero'}}

こっちが正解。

>>> tt['c'] = t.copy()
>>> tt['a'][3] = 'three'
>>> tt['c']
{2: 'two', 1: 'one', 0: 'zero'}
 

Comments:

Post a Comment:
  • HTML Syntax: Allowed

[Masubi]
Copyright © 1998-2009 Tomoaki TSUMURA. Powered by Apache Roller 4.0.1.
tomoaki@tsumura.info