from itertools import groupby
from operator import itemgetter
distance_list = [('Brahmadatta Devadatta', 0.12844036697247707, '2, 6', '0, 10'),
('Brahmadatta Devadatta', 0.07339449541284404, '2, 6', '1, 9'),
('Brahmadatta Sujata', 0.11009174311926606, '2, 6', '4, 8')]
for key, value in groupby(sorted(distance_list), key=itemgetter(0)):
print map(itemgetter(1), value) #works for printing float numbers
print map(itemgetter(2), value) # returns an empty list
为什么itemgetter返回空列表而不是返回相应的字符串
预期输出:
2, 6
2, 6
2, 6
生成输出:
[ ]
[ ]
[ ]