我对 Python 中的列表连接有疑问,我有这段代码:
def lista():
word = sys.argv[1]
l = []
m = []
for file_name in sys.argv[2:]:
with open(file_name, "r") as f:
for line in f:
l + [len(re.findall(word, line))] #doesn't work
m.append(len(re.findall(word, line))) #works
print l
print m
return l
当我运行这个函数时,我总是得到空列表 l,但是 m 中有元素,为什么 l+[elem] 对我不起作用?