Python itemgetter打印空列表而不是字符串

时间:2013-03-24 22:07:24

标签: python python-2.7

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

生成输出:

[ ]  
[ ]  
[ ] 

0 个答案:

没有答案