Skip to content

Instantly share code, notes, and snippets.

@kitten77
Last active December 17, 2018 09:27
Show Gist options
  • Save kitten77/2ca469ebfd3314c47132331dfa5f0dd9 to your computer and use it in GitHub Desktop.
Save kitten77/2ca469ebfd3314c47132331dfa5f0dd9 to your computer and use it in GitHub Desktop.
quick collection counter
import collections
string = "aaaBBBcccDDD"
line = str()
counter = collections.Counter(string)
for key, value in counter.items():
line +=(f'{key}: {value} ')
print(line)
@kitten77
Copy link
Author

import collections
...
... string = "aaaAAAABBBbbbcccCCCDDDdddEEffFFe"
... line = str()
... counter = collections.Counter(string)
... for key, value in counter.items():
... line +=(f'{key}: {value} ')
... print(line)
...
a: 3 A: 4 B: 3 b: 3 c: 3 C: 3 D: 3 d: 3 E: 2 f: 2 F: 2 e: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment