Nov-12-2023, 02:31 PM
Good morning,
I'm trying to create a number of variables that is dynamic.
Lets say I have a string
sentence = "All work and no play makes Jack a dull boy."
and I count the number of words in the string using a counting scheme of some sort and arrive at a value of 10.
I then want to create 10 variables and store each separate word into a different variable.
I think I could use a function like this:
while i < num_vars:
var_name = ??? - I think I could just loop through numbers and concatenate for a name. Ie.. "var_" concatenated with i , then iterate i
var_value = ??? - Should I use some string split function in python, or assign to an array and use array functions?
exec(var_name + " = " + var_value)
Thanks again for the help and I hope this makes sense.
I'm trying to create a number of variables that is dynamic.
Lets say I have a string
sentence = "All work and no play makes Jack a dull boy."
and I count the number of words in the string using a counting scheme of some sort and arrive at a value of 10.
I then want to create 10 variables and store each separate word into a different variable.
I think I could use a function like this:
while i < num_vars:
var_name = ??? - I think I could just loop through numbers and concatenate for a name. Ie.. "var_" concatenated with i , then iterate i
var_value = ??? - Should I use some string split function in python, or assign to an array and use array functions?
exec(var_name + " = " + var_value)
Thanks again for the help and I hope this makes sense.