Python更新行

时间:2016-04-04 12:48:48

标签: python

我有这段代码。

START_STAT =(
            [ 4, 3, 6, 3, ],
            [ 3, 3, 4, 6, ],
            [ 3, 5, 5, 3, ],
            [ 4, 6, 3, 3, ],
            [ 4, 3, 6, 3, ],
            [ 3, 3, 4, 6, ],
            [ 3, 5, 5, 3, ],
            [ 4, 6, 3, 3, ],
            )

我想用一行更新一行

START_STAT.update{[ 6, 2, 2, 6, ]}

那里有什么问题? 我也试过+但同样的错误。

START_STAT +={[ 6, 2, 2, 6, ]}

有什么问题?

2 个答案:

答案 0 :(得分:2)

START_STAT =(..)

元组是immutable

您可以将list用于此目的:

START_STAT = []
START_STAT.append([ 6, 2, 2, 6, ])

答案 1 :(得分:1)

如果您使用list代替dict,如Xi_所示,那么您也可以这样做:

import numpy as np
START_STAT =(
            [ 4, 3, 6, 3, ],
            [ 3, 3, 4, 6, ],
            [ 3, 5, 5, 3, ],
            [ 4, 6, 3, 3, ],
            [ 4, 3, 6, 3, ],
            [ 3, 3, 4, 6, ],
            [ 3, 5, 5, 3, ],
            [ 4, 6, 3, 3, ],
            )

lst = ([ 6, 2, 2, 6, ])
np.vstack((START_STAT,lst))