fork download
  1. word = "aaaaabbaaddkamaaaaaad"
  2.  
  3. buf = [['', 0]]
  4. for c in word:
  5. if c == buf[-1][0]:
  6. buf[-1][1] += 1
  7. else:
  8. buf.append([c, 1])
  9.  
  10. print(''.join(["{}{}".format(c, n) for c,n in buf[1:]]))
  11.  
Success #stdin #stdout 0.02s 9296KB
stdin
Standard input is empty
stdout
a5b2a2d2k1a1m1a6d1