Skip to content

Instantly share code, notes, and snippets.

@KaiserKatze
Created October 20, 2018 07:36
Show Gist options
  • Select an option

  • Save KaiserKatze/9140eb4637dfdf689a949159abb66b84 to your computer and use it in GitHub Desktop.

Select an option

Save KaiserKatze/9140eb4637dfdf689a949159abb66b84 to your computer and use it in GitHub Desktop.
Simple digest algorithm demonstration
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
def simple_digest(input_string):
chars = {}
for c in input_string:
chars[c] = chars.get(c, 0) + 1
items = iter(sorted(chars.items()))
pairs = map(lambda pair: [str(pair[1]), pair[0],], items)
result = itertools.chain.from_iterable(pairs)
result = ''.join(result)
return result
if __name__ == '__main__':
input_string = 'KNYSDFDJBYSDFDJYQ'
result = simple_digest(input_string)
print(result)
# Expected output:
assert(result == '1B4D2F2J1K1N1Q2S3Y')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment