0

imagine I have this Python Code

text1 = 'hello I need to split this string'
text1_split = text1.split(' ')

Now that I have split the string into the seven parts how can I count them and then assign each string to a variable that the program creates, maybe result_1, result_2, result_x.... and so on? Or I guess I just need to analyse each section individually and report each result as a different variable so if that way around it is easier to explain I am down for that too! Thanks for the help guys I appreciate it!!

cs95
  • 379,657
  • 97
  • 704
  • 746
  • 7
    Why would you want to unpack the list into an unknown number of variables when you could just keep them in a list and iterate over them/index as needed? – cs95 Oct 15 '17 at 06:45
  • 1
    Trust me, you really don't want to create variables dynamically like that. For further info on this important topic please see [How do I create a variable number of variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables) and [Why you don't want to dynamically create variables](http://stupidpythonideas.blogspot.com.au/2013/05/why-you-dont-want-to-dynamically-create.html). – PM 2Ring Oct 15 '17 at 07:22

0 Answers0