辞書と関数について検証してみました。
勉強になります。ありがとうございます。
C:\Python22jp>python
Python 2.2.3 (SJIS enhanced) (#42, Jun 8 2003, 01:46:45) [MSC 32 bit (Intel)] o
n win32
Type "help", "copyright", "credits" or "license" for more information.
>>> c={}
>>> for i in range(5):
... c[i]=[]
...
>>> c
{0: [], 1: [], 2: [], 3: [], 4: []}
>>> c[0]=[1,2,3]
>>> c
{0: [1, 2, 3], 1: [], 2: [], 3: [], 4: []}
>>> def add(a,b):
... return [a[i]+b[i] for i in range(len(a))]
...
>>> c[1]=[3,2,1]
>>> add(c[0],c[1])
[4, 4, 4]
>>> c
{0: [1, 2, 3], 1: [3, 2, 1], 2: [], 3: [], 4: []}
>>> c[2]=add(c[0],c[1])
>>> c
{0: [1, 2, 3], 1: [3, 2, 1], 2: [4, 4, 4], 3: [], 4: []}
>>> import math
>>> def normalize(x,y,z):
... s=math.sqrt(x*x+y*y+z*z)
... if s==0:s=1
... else: s=1.0/s
... return x*s,y*s,z*s
...
>>> c[0]
[1, 2, 3]
>>> normalize(1,2,3)
(0.2672612419124244, 0.53452248382484879, 0.80178372573727319)
>>> normalize(c[0])
Traceback (most recent call last):
File "
TypeError: normalize() takes exactly 3 arguments (1 given)
>>> normalize(*c[0])
(0.2672612419124244, 0.53452248382484879, 0.80178372573727319)
>>> normalize(4,4,4)
(0.57735026918962584, 0.57735026918962584, 0.57735026918962584)
>>> normalize(*add(c[0],c[1]))
(0.57735026918962584, 0.57735026918962584, 0.57735026918962584)
>>>
- -
- -