例 2
此示例说明了如果我们不指定任何默认密钥,将如何选择默认密钥
c = groupby(['goat', 'dog', 'cow', 1, 1, 2, 3, 11, 10, ('persons', 'man', 'woman')])
dic = {}
for k, v in c:
dic[k] = list(v)
dic
结果是
{1: [1, 1],
2: [2],
3: [3],
('persons', 'man', 'woman'): [('persons', 'man', 'woman')],
'cow': ['cow'],
'dog': ['dog'],
10: [10],
11: [11],
'goat': ['goat']}
请注意,元组作为一个整体计为此列表中的一个键