We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0dd713c commit cdb3a6eCopy full SHA for cdb3a6e
1 file changed
newcodes/answers/q71.py
@@ -0,0 +1,23 @@
1
+#!/usr/bin/env python
2
+# coding=utf-8
3
+
4
+class StatWrod(dict):
5
+ def add(self, item, increment=1):
6
+ self[item] = increment + self.get(item, 0)
7
+ def counts(self, reverse=False):
8
+ aux = [(self[k], k) for k in self]
9
+ aux.sort()
10
+ if reverse:
11
+ aux.reverse()
12
+ return [(v, k) for v,k in aux]
13
14
+if __name__ == "__main__":
15
+ sentence = "Don't stay in bed, unless you can make money in bed."
16
+ words = sentence.split()
17
+ c = StatWrod()
18
+ for word in words:
19
+ c.add(word)
20
+ print("Ascending count:")
21
+ print(c.counts())
22
+ print("Descending count:")
23
+ print(c.counts(reverse=True))
0 commit comments