name = raw_input("Enter file:")
hr = list()
freq = list()
i=0
k=0
handle = open(name)
for line in handle:
if line.startswith('From'):
h1 = line.split()[5].split(':')[0]
if h1 not in hr:
hr[i] = h1
i=i+1
for j in range(hr):
for line in handle:
if line.startswith('From'):
h2 = line.split()[5].split(':')[0]
if hr[j] == h2:
freq[j] = k+1
for l in range(hr):
print hr[l],freq[l]
答案 0 :(得分:1)
您引用列表中的第一项" h [0]"列表中没有项目。 Python不会隐式附加项目。请改用:
hr.append(h1)