Created
March 2, 2018 17:59
-
-
Save kirillsulim/332be668037c9b21717638ca63b85557 to your computer and use it in GitHub Desktop.
Count number of occurrences of a specific digit with order keeping
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 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