title: Assigning variables to split strings
body: <p>I am trying to split a string into several variables to eventually send each one as an instruction for one of six stepper motors. A string will  be in a format like so:</p>
  <blockquote>
  <p>D2 R' D' F2 B D R2 D2 R' F2 D' F2 U' B2 L2 U2 D R2 U</p>
  </blockquote>
  <p>The issue is the steps within the string (e.g. D2 or R' or B) are all varying in length, so using step as a fixed length provides issues when recalling the individual sections (the varying lengths means that sometimes I will get part of one solution or a blank space then a letter). Also using something like unpacking doesn't work as the amount of steps in the string varies. So, how can I cut up a string like the one shown below, so I can assign each step to a individual variable?</p>
  <p>From looking at a previous question (<a href="https://stackoverflow.com/questions/13749701/python-split-string-into-smaller-chunks-and-assign-a-variable">Python - split string into smaller chunks and assign a variable</a>) I have realised I can do something along these lines:</p>
  <pre><code>finalstate = input(&quot;enter solution: &quot;)
  finalstate.split
  step = 2
  solution_steps = [finalstate[i:i+step] for i in range(0, len(finalstate),step)]
  </code></pre>
  <p>And then call upon the different chunks of the solution like so:</p>
  <pre><code>print(Solution_steps[0])
  </code></pre>
  <p>However, in that solution they wanted the string to be separated by a determined length and mine will vary.</p>