V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  NICCEEEE  ›  全部回复第 1 页 / 共 1 页
回复总数  2
@jko123 同感。最近莫名其妙开始降智的感觉,其他平台也有不少人反馈类似的现象
2018 年 6 月 16 日
回复了 wsds 创建的主题 › Python › Python 菜鸡请教
import collections

d = """a, 1.324171
b, 0.000126
c, 1.970941
a, 1.469649
b, 0.000124
c, 0.512929
a, 1.290920
b, 0.000118
c, 0.259524
a, 0.495958
b, 0.000123
c, 0.910949
a, 1.268038
b, 0.000118
c, 1.016419
a, 1.856081
b, 0.000120
c, 1.400075
a, 1.314131
b, 0.000140"""

L = [(i[0], i[3:]) for i in d.split('\n')]
data_dict = collections.defaultdict(int)

for i, j in L:
data_dict[i] += float(j)

print(data_dict)
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1668 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 16:04 · PVG 00:04 · LAX 08:04 · JFK 11:04
♥ Do have faith in what you're doing.