-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountWords.py
47 lines (37 loc) · 1.14 KB
/
CountWords.py
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
import random
import numpy
from numba import njit
from timeit import timeit
#============================= Word Count =============================
def generate_file():
words = ['CienciaComputacion', 'hola mundo', 'cs2019', 'Arequipa','peru','lunes','Cloud']
file = open("texto1.txt","w+")
for i in range(100000000):
r = random.randint(0, len(words)-1)
# print(r)
file.write(words[r] + " ")
file.close
print("final")
def CountWords():
dic = dict()
file = open('words1.txt','r')
for line in file:
#print(line)
words = line.split()
for w in words:
if w in dic:
dic[w] +=1
else:
dic[w]=1
# print(timeit())
print(dic)
# generate_file()
CountWords()
#================================ Eejmplo palaralelizacion ====================
# x = numpy.random.random((1000,1000))
# y = numpy.random.random((1000,1000))
# def do_trig(x,y):
# z = numpy.sin(x**2) + numpy.cos(y)
# return z
# do_trig_jit_par = njit(parallel = True)(do_trig)
#===================================================================0