假设我有以下元组:
('eggs', 20, 30)
('eggs', 40, 23)
('eggs', 10, 24)
('apple', 2, 22)
('apple', 42, 3)
我希望字典的外观像这样:
{
eggs: [[20, 30], [40,23], [10,24]],
apple: [[2,22], [42,3]]
}
我该如何获取这个?
我尝试了以下方法:
dic = {}
for d in data:
dic[d[0]] += [[d[1], d[2]]
#d[0] being eggs or apple, d[1] and d[2] being the numbers