Ramy
Ramy

Reputation: 174

Python update lines

I have this code.

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, ],
            )

And i want to update one with one more line

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

What is wrong there ? I tried also with + but same , error.

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

What is wrong?

Upvotes: 0

Views: 64

Answers (2)

Joe T. Boka
Joe T. Boka

Reputation: 6581

If you use a list instead of a dict, as Xi_ suggested, then you can also do this:

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))

Upvotes: 1

xiº
xiº

Reputation: 4687

START_STAT =(..)

Tuple is immutable.

You could use list for that purpose:

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

Upvotes: 2

Related Questions