I'm relatively new to coding in python so go easy on me.
I want to create integer variables with the names of these variables based off elements of a string array and set them all to zero to start with (in order to save me manually coding 20 variables out). The string array is shown below.
filterKeywords = ['IBM', 'Microsoft', 'Facebook', 'Yahoo', 'Apple',
'Google', 'Amazon', 'EBay', 'Diageo',
'General Motors', 'General Electric', 'Telefonica', 'Rolls Royce',
'Walmart', 'HSBC', 'BP',
'Investec', 'WWE', 'Time Warner', 'Santander Group']
I don't want the variable names to be exactly the name of the element in the array
, however, I want the variable names to contain the elements from the array
, for example: for the string
element 'apple' I want my variable name to be 'applePositive'. I have tried to implement this and here it is below (I'm not sure if it is the correct format or not).
for word in filterKeywords:
[word + "Positive"] = 0
I'm getting a "cannot assign to operator" error with this and I've tried also to cast it to an int
but it doesn't work either.
Any help would be much appreciated!