Skip to content

Instantly share code, notes, and snippets.

@kirillsulim
Created March 2, 2018 17:59
Show Gist options
  • Save kirillsulim/332be668037c9b21717638ca63b85557 to your computer and use it in GitHub Desktop.
Save kirillsulim/332be668037c9b21717638ca63b85557 to your computer and use it in GitHub Desktop.
Count number of occurrences of a specific digit with order keeping
from collections import Counter
def convert(value):
value = str(value)
cnt = Counter(value)
res = []
for el in cnt:
res.append(el)
res.append(str(cnt.get(el)))
return int("".join(res))
def equals(actual, expected):
if actual == expected:
return True
else:
print("Expected: '{}', but was '{}'".format(expected, actual))
return False
assert equals(convert(1234), 11213141)
assert equals(convert(11213141), 15213141)
assert equals(convert(1121231234), 14233241)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment