gpt4 book ai didi

python - groupby() 给出一个空列表

转载 作者:太空狗 更新时间:2023-10-30 01:54:48 27 4
gpt4 key购买 nike

<分区>

我执行了以下脚本:

from itertools import groupby
from pprint import pprint as prnt
dt = [('23271800', 0.00066790780636275307),
('23271812', 0.0010018617095441298),
('26112103', 0.00066790780636275307),
('27111616', 0.0056772163540834012),
# ... many lines deleted ...
('40161500', 0.00040074468381765189)
]

agg = groupby(dt, lambda x: x[0])
lst = list(agg)
lst1 = map(lambda x: (x[0], list(x[1])), lst)
prnt(lst1)

对于项目 '23271800',它应该将 [('23271800', 0.00066790780636275307)] 报告为其对应的 groupby 项目。但是,我得到的输出不正确。

[('23271800', []),
('23271812', []),
('26112103', []),
('27111616', []),
# ... many lines deleted ...
('40161500', [('40161500', 0.00040074468381765189)])]

如果我在这里做错了什么,需要帮助来理解。

PS:代码粘贴:http://codepad.org/cCd8DfoT

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com