How do you keep a variable the same in python, even if the value it is refering to changes? -


this question has answer here:

so have project school i'm making , in need make change list named board. have return changes have made in form of sequence. defind "board" list of tuples , sets , made function changes specific set in "board", made function looks this:

def function (board,pos): #pos tuple (x,y)     begin_open_positions = board[2]      disclose_help(board,pos)     #this function changes board      end_open_positions = board[2]     added_pos = begin_open_positions-end_open_positions     return added_pos #board @ start = [(4, 4), [(0, 0)], set(), ((0, 0), (0, 1), (0, 1))] #board @ end =[(4, 4), [(0, 0)], {(1, 2), ... ,(1, 1)}, ((0, 0),...)] 

the question why begin_open_position change , how can make doesnt change , stays (in case) set().

the disclose function adds positions board[2]

edit: tried use copy.copy(x) didnt work

maybe need:

import copy b = copy.deepcopy(a) # apply changes `a` not affect `b` 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -