Re: [問題] txt內容切割加總
※ 引述《PTT007 (優質單身好男人)》之銘言:
: 如果我有一個txt內容如下:
: 0.01
: 0.02
: 0.03
: 0.09
: 1.03
: 1.02
: 1.01
: 我想將 0.X 和 1.X 各自累加起來
: 輸出結果為 0.15 和 3.06
# a functional solution
import itertools
for key, group in itertools.groupby(map(float, open('in.txt')), int):
print key, sum(group)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.135.71.186
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1414505076.A.2BC.html
推
10/29 01:00, , 1F
10/29 01:00, 1F
推
11/06 10:20, , 2F
11/06 10:20, 2F
→
11/06 11:03, , 3F
11/06 11:03, 3F
討論串 (同標題文章)