小编Imr*_*fin的帖子

python中文本分析器代码的时间复杂度

letterList = ["a", 0, "b", 0, "c", 0, "d", 0, "e", 0, "f", 0, "g", 0, "h", 0, "i", 0,  "j", 0, "k", 0, "l", 0, "m", 0, "n", 0, "o", 0, "p", 0, "q", 0, "r", 0, "s", 0, "t", 0, "u", 0, "v", 0, "w", 0, "x", 0, "y", 0, "z", 0]
letterCount = 0
wordList = [None]
wordCount = 0
Count = 0
wordIndex = [0]
itext = cleaner(raw_input("enter itext please")).split()
print itext
for iword in itext: …
Run Code Online (Sandbox Code Playgroud)

python algorithm time-complexity

2
推荐指数
1
解决办法
325
查看次数

为什么这个python代码的执行时间会增加每个调用?

import time
word = {"success":0, "desire":0, "effort":0, ...}
def cleaner(x):
    dust = ",./<>?;''[]{}\=+_)(*&^%$#@!`~"
    for letter in x:
        if letter in dust:
            x = x[0:x.index(letter)]+x[x.index(letter)+1:]
        else:
            pass
    return x #alhamdlillah it worked 31.07.12
print "input text to analyze"
itext = cleaner(raw_input()).split()
t = time.clock()
for iword in itext:
    if iword in word:
        word[iword] += 1
    else:
        pass
print t
print len(itext)
Run Code Online (Sandbox Code Playgroud)

每次我调用代码,t都会增加.任何人都可以解释这背后的基本概念/原因.也许在系统过程方面?非常感谢,编程小伙子们.

python performance time

-1
推荐指数
1
解决办法
294
查看次数

标签 统计

python ×2

algorithm ×1

performance ×1

time ×1

time-complexity ×1