[Tutor] Slow program
Diego Prestes
lobow@brturbo.com
Wed Dec 11 06:51:01 2002
--409492443.1039607349545.JavaMail.nobody.webmail2.brturbo.com
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hello,
Im trying to make a program that take a text and test whats the two words that apeer more in the text together, but when I do this code it is to slow. I think its because of that create many times the same text (var b), but I dont find any better program. Someone could give a hand?
Diego
def calc(b):
dic={}
for x in range(len(b)-1):
if dic.has_key(b[x]+' '+b[x+1]) == 0:
c = 0
for y in range(len(b)-1):
if b[x] == b[y] and b[x+1] == b[y+1]:
c=c+1
dic[b[x]+' '+b[x+1]] = c
ma=0
for x in range(len(dic)):
if dic.values()[x] > ma:
ma = dic.values()[x]
for x in range(len(dic)):
if dic.values()[x] == ma:
print "%s -> %d" % (dic.keys()[x],dic.values()[x])
--409492443.1039607349545.JavaMail.nobody.webmail2.brturbo.com--