# -*- coding: utf-8 -*-
from collections import Counter
import itertools, collections
ListeA=['it', 'was', 'the', 'besttttttttttttttrtrtrtrtrttrtr', 'of', 'times', 'it', 'was',
'the', 'worst', 'of', 'times', 'it', 'was', 'the', 'age', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx'
'of', 'wisdom', 'it', 'was', 'the', 'age', 'of', 'xx'
'foolishness']
index = collections.defaultdict(list);
for value, key in enumerate(ListeA):
index[key].append(value)
for key1,value1 in index.items():
if len(value1)>=4:
print value1
输出不正确。我的代码有什么问题。输出似乎为什么打印出错误的结果。 python enumerate,计数器
[0, 6, 12, 27]
[16, 17, 18, 19, 20, 21, 22, 23, 24]
[2, 8, 14, 29]
[1, 7, 13, 28]
我将号码添加到阅读方便ListeA=[0'it', 1'was', 2'the', 3'besttttttttttttttrtrtrtrtrttrtr', 4'of', 5'times', 6'it', 7'was', 8'the', 9'worst', 10'of', 11'times', 12'it', 13'was', 14'the', 15'age', 16'xx', 17'xx', 18'xx', 19'xx', 20'xx', 21'xx', 22'xx', 23'xx', 24'xx', 25'xx' 26'of', 27'wisdom', 28'it', 29'was', 30'the', 31'age', 32'of', 33'xx' 34'foolishness']
它有什么问题?准确地说明你预期的产出*。 –