It is difficult to understand your context with this code fragment, but what it seems is that you just want to make a "replace" in the list according to the values of the variables Vnomevalor, Vcorvalor, etc, isn’t it? at least looking at the code that you passed, that’s what it looks like. By the way, it seems to me that you came from another language, I recommend you see the PEP8, the style guide for python encoding.
I developed a function that receives a list and a dictionary with the variables (in pythonic style) that you have posted and replace in the list according to the value of the variable, as I understand it, the value of the list will be changed to 1 if the value of the variable is equal to 1, then it was like this:
def get_list(_data, _list1):
if _data['cor_valor']['value']==1:
_list1[ data['cor_valor']['pos'] ]
if data['cpf_valor']['value']==1:
_list1[data['cpf_valor']['pos']]=1
if data['mail_valor']['value']==1:
_list1[data['mail_valor']['pos']]=1
if data['nome_valor']['value']==1:
_list1[data['nome_valor']['pos']]=1
return _list1
data = {'cor_valor': {'pos': 1, 'value': 0},
'cpf_valor': {'pos': 2, 'value': 1},
'mail_valor': {'pos': 3, 'value': 0},
'nome_valor': {'pos': 0, 'value': 1}
}
list1 = [0,0,0,0]
list1 = get_list(data, list1)
print (list1)
[1, 0, 1, 0]
See the code working here.
After a few hours that I posted the above solution, I returned and saw how much verbiage it got, so I decided to reduce it, see:
data = {'cor_valor': {'pos': 1, 'value': 0},
'cpf_valor': {'pos': 2, 'value': 1},
'mail_valor': {'pos': 3, 'value': 0},
'nome_valor': {'pos': 0, 'value': 1}
}
list0 = [0,0,0,0]
def get_list_v2(_data, _list1):
for d in _data:
if _data[d]['value']==1:
_list1[data[d]['pos']]=1
return _list1
list1 = get_list_v2(data, list0)
print (list1)
Look at this new code here.
just put
self.v
that you will be able to use it in every class, including, you can usev[0] = 1
to replace the value of the first element to 1– Antony Gabriel