Created
May 23, 2016 01:35
-
-
Save alpham/c02ee51f6006236a415f56b54103debc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
def pack(arr): | |
uniqe_items = [] | |
count_items = [] | |
for i in groupby(arr): | |
if i[0] not in uniqe_items: | |
count_items.append(len(list(i[1]))) | |
uniqe_items.append(i[0]) | |
return ["{}:{}".format(num, count) for num, count in zip(uniqe_items, count_items)] | |
print pack([5, 5, 5, 7, 7, 3, 4, 7]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment