title: Run Length Encoding in Python with List Comprehension
body: <p>I have a more basic Run Length Encoding question compared to many of the questions about this topic that have already been answered. Essentially, I'm trying to take the string</p>
  
  <pre><code>string = 'aabccccaaa'
  </code></pre>
  
  <p>and have it return</p>
  
  <pre><code>a2b1c4a3
  </code></pre>
  
  <p>I thought that if I can manage to get all the information into a list like I have illustrated below, I would easily be able to return a2b1c4a3</p>
  
  <pre><code>test = [['a','a'], ['b'], ['c','c','c','c'], ['a','a','a']]
  </code></pre>
  
  <p>I came up with the following code so far, but was wondering if someone would be able to help me figure out how to make it create the output I illustrated above. </p>
  
  <pre><code>def string_compression():
      for i in xrange(len(string)):
          prev_item, current_item = string[i-1], string[i]
          print prev_item, current_item
          if prev_item == current_item:
              &lt;HELP&gt;
  </code></pre>
  
  <p>If anyone has any additional comments regarding more efficient ways to go about solving a question like this I am all ears!</p>