I'm looking for a way to assign variables dynamically using loop & functions in Python. One way I can do so in R is by using eval(parse(text=text))
. For example, assuming I have this code:
var <- c('First','Second','Third')
for (i in 1:length(var)){
text <- paste0("Variable_", var[i], " <- ", i)
eval(parse(text = text))
}
And my desired output is as follow:
> Variable_First
[1] 1
> Variable_Second
[1] 2
> Variable_Third
[1] 3
What is the equivalent way of doing such in Python?
Thanks in advance!