The following solution does exactly what you have specified, using the built-in exec()
function. However, you should never ever ever use it! It is hideously unsafe, and I am only posting it for completeness' sake. Use the solution after it instead.
for i in range(len(s)):
exec(s[i] + "=" + str(a[i]))
What you should do is use a dictionary:
myDictionary = dict(zip(s, a))
What this does is it matches each element of the lists s
and a
into key-value pairs in a dictionary by their index (meaning that they are matched based on their order).
And then you can do:
>>> print(myDictionary["w"])
2