5 kyu

uniq -c (UNIX style)

469 of 855x-way

Description:

Implement a function which behaves like the 'uniq -c' command in UNIX.

It takes as input a sequence and returns a sequence in which all duplicate elements following each other have been reduced to one instance together with the number of times a duplicate elements occurred in the original array.

Example:

['a','a','b','b','c','a','b','c'] --> [['a',2],['b',2],['c',1],['a',1],['b',1],['c',1]]
['a','a','b','b','c','a','b','c'] --> [('a',2),('b',2),('c',1),('a',1),('b',1),('c',1)]
Arrays
Algorithms

More By Author:

Check out these other kata created by x-way

Stats:

CreatedSep 2, 2013
PublishedSep 2, 2013
Warriors Trained1357
Total Skips91
Total Code Submissions5116
Total Times Completed855
JavaScript Completions469
Python Completions399
Total Stars26
% of votes with a positive feedback rating89% of 216
Total "Very Satisfied" Votes175
Total "Somewhat Satisfied" Votes33
Total "Not Satisfied" Votes7
Ad
Contributors
  • x-way Avatar
  • jhoffner Avatar
  • suic Avatar
  • albertogcmr Avatar
  • farhanaditya Avatar
Ad