-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_test.py
More file actions
49 lines (39 loc) · 1.1 KB
/
func_test.py
File metadata and controls
49 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import random
import sys
# functions = {
# "sum": "a+b",
# "mul": "a*b",
# }
# print(eval(cmd,{"a":1,"b":3})
def random_sentence_spout():
yield random.choice(["the cow jumped over the moon", "an apple a day keeps the doctor away",
"four score and seven years ago", "snow white and the seven dwarfs", "i am at two with nature"])
def sentence_splitter(inputs):
words_str = inputs
# print "word str", words_str
words = words_str.split(' ')
for word in words:
# print "word s", word
yield word
def word_counter(inputs):
word = inputs[0]
counts = inputs[1]
# print "word c", word
count = counts.get(word)
if count is None:
count = 0
count += 1
counts[word] = count
return counts
# print(exec(cmd_def,{"a":1,"b":3}))
# print(exec(cmd,{"a":5,"b":8}))
# print(exec(cmd_return,{"a":1,"b":3}))
if __name__ == "__main__":
counts = {}
args = sys.argv[1:]
for a in random_sentence_spout():
for b in sentence_splitter(a):
c = (b,counts)
for d in word_counter(c):
pass
print counts