Created
October 1, 2012 14:19
-
-
Save defuz/3812061 to your computer and use it in GitHub Desktop.
occurences of each character in a string
This file contains 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
# for http://stackoverflow.com/questions/12674193/python-no-of-occurences-of-each-character-in-a-string | |
def xx(string): | |
i, d = 0, {} | |
while i < 127: | |
char = chr(i) | |
d[char] = string.count(char) | |
i += 1 | |
return d | |
# printable characters only: | |
from string import printable | |
def xxxx(string): | |
return {c: string.count(c) for c in printable} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment