title: how to count repeated characters in a string in python
body: <p>Write a python function which performs the run length encoding for a given String and returns the run length encoded String.</p>
  
  <p>I tried it using looping but couldn't get the expected output.</p>
  
  <pre><code>def encode(message):    
      #Remove pass and write your logic here
      count=0
      encoded_message=[]
      for char in range(0,len(message)-1,1):
          count=1
          while(message[char]==message[char+1]):
  
               count=count+1;
               char=char+1
          encoded_message.append(str(count)+message[char])
  
      return encoded_message
  
  encoded_message=encode("ABBBBCCCCCCCCAB")
  print(' '.join(encoded_message))
  </code></pre>
  
  <p>expected output is <code>1A4B8C1A1B</code>.
  what I got is <code>1A 4B 3B 2B 1B 8C 7C 6C 5C 4C 3C 2C 1C 1A</code></p>