VC_I=[1,2,4,3]
for i in range(len(VC_I)):
print(VC_i=[])
TypeError: 'VC_i' is an invalid keyword argument for this function
VC_I=[1,2,4,3]
for i in range(len(VC_I)):
print(VC_i=[])
TypeError: 'VC_i' is an invalid keyword argument for this function
Why dont you just use a dictionary for this purpose?
VC_I=[1,2,4,3]
x = {}
for i in range(len(VC_I)):
x[VC_I[i]] = [value, you, want]
To access use:
print(x["key name"])
To do what you wanted,
x = dict(zip(VC_I, PAYLOAD_IN))
You need to use special module to get variable name. See here: Getting the name of a variable as a string
BTW, to make your example correctly iterating just the values do the following:
VC_I=[1,2,4,3]
for i in range(len(VC_I)): print(VC_I[i])
I don't know if you need this, but you can use the locals()
to do this. For example, given your code:
VC_I=[1,2,4,3]
names_dict = dict(locals()) #Preserve a copy of all local variables
for key, val in names_dict.items():
if val == VC_I:
print('The variable name is:', key)
which will output, as you have guessed:
The variable name is: VC_I
However, this will only work if you are working with local variables. It also wouldn't work for variables with the exact same values. Take note.
edit You can even do this:
for key, val in names_dict.items():
if val == VC_I:
print(key, ' = ', val)
which should give you:
VC_I = [1, 2, 3, 4]
I think you want to create list like VC_1, VC_2, ... check this code
VC_I=[1,2,4,3,4,5,6,7,8]
PAYLOAD_IN=[ 'a2','123','21','1a','ae','23','12','ef']
for i in VC_I:
name = 'VC_'+str(i)
print(name) # here name variable is string
name = list()
print(name) # here name variable is list
print(type(name)) # checking data type of variable name
Answer for your specific question
for i, j in zip(VC_I, PAYLOAD_IN):
name = 'VC_' + str(i)
name = list()
name.append(j)
print(name)