def get_word_count(wordlist, final):
regex = []
count = [[] for x in xrange(len(wordlist))]
frequency = []
regex = makeregex(wordlist)
for i in range(len(final)-1):
size = os.stat(final[i]).st_size
fil = open(final[i])
if(fil):
print final[i] + " read!"
data = mmap.mmap(fil.fileno(), size, access=mmap.ACCESS_READ)
for j in range (len(wordlist)):
count[j].append(re.findall(regex[j], data))
fil.close()
for k in range(len(wordlist)):
frequency.append(sum(count[k]))
print frequency
count
是一个列表列表,每个列表都存储了一些数字。我希望将每个列表的总和作为一个元素存储到一个新列表中frequency
当我运行代码时出现错误:
Traceback (most recent call last):
File "C:\Users\Animesh\Desktop\_zipf.py", line 52, in <module>
get_word_count(wordlist, final)
File "C:\Users\Animesh\Desktop\_zipf.py", line 32, in get_word_count
frequency.append(sum(count[k]))
TypeError: unsupported operand type(s) for +: 'int' and 'list'
我应该在我的代码中更改什么?请帮忙