Declare python variables from 2 lists inside a loop

Viewed 15

The task:

The function accepts 2 lists (string list and integer list) and returns the third list, where strings are the variable names and the integers are the values assigned to them.

example:

list_1 = ['a', 'b', 'c']
list_2 = [1, 2, 3]

def declare_var(list_1, list_2):
    var_list = []

    # here happens the magic assignations where:  a = 1,  b = 2 , c = 3

    return var_list

Now, if we call the function:

declare_var(list_1, list_2)

And then print out each variable from the returned list:

print(var_list[0])
print(var_list[1])
print(var_list[2])

We should get printed:

1, 2, 3

it's easy to create a dictionary where lists make key:value pair and are bind that way, but how would we transform them to variable = value pairs?

0 Answers
Related