We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents a7480c1 + bc33158 commit b198a49Copy full SHA for b198a49
stringPopulation
@@ -0,0 +1,19 @@
1
+from collections import defaultdict
2
+import string
3
+def extract_popular(textstring):
4
+ """
5
+ Input: string
6
+ Output: dictionary with counts for each character in a string
7
8
+ d = defaultdict(int)
9
+ exclude = set(string.punctuation)
10
+ textstring = textstring.lower()
11
+ textstring = ''.join(ch for ch in textstring if ch not in exclude)
12
+ for c in textstring:
13
+ d[c] += 1
14
+ counts = [(d[c], c) for c in d]
15
+ counts.sort()
16
+ counts.reverse()
17
+ return counts
18
+print(extract_popular("A man, a plan, a canal: Panama"))
19
+print(extract_popular("Testing, attention please"))
0 commit comments