title: python: dedup and count a given list
body: <p>I am using the following code to dedup and count a given list: </p>
  
  <pre><code>def my_dedup_count(l):
      l.append(None)
      new_l = []
      current_x = l[0]
      current_count = 1
      for x in l[1:]:
          if x == current_x:
              current_count += 1
          else:
              new_l.append((current_x, current_count))
              current_x = x
              current_count = 1
  
      return new_l
  </code></pre>
  
  <p>With my testing code:</p>
  
  <pre><code>my_test_list = ['a','a','b','b','b','c','c','d']
  my_dedup_count(my_test_list)
  </code></pre>
  
  <p>result is:</p>
  
  <pre><code>[('a', 2), ('b', 3), ('c', 2), ('d', 1)]
  </code></pre>
  
  <p>The code is doing fine and the output is correct. However, I feel my code is quite lengthy and am wondering would anyone suggest a more elegant way to improve the above code? Thanks!</p>