python中查找列表中的数值_Python:在列表中查找值

def sum_points(point_list):

sol = []

sum = 0.0

for x in point_list:

sum += x

sol.append(sum)

return sol

def main():

with open("example.json") as f:

for line in f:

result = json.loads(line)

if('text' and 'place' in result.keys()) and (type(result['place']) is dict):

place_user = result['place']

tw_user = result['text']

words = tw_user.encode("utf-8").split()

points = dict.fromkeys(words,0)

with open("wordlist.txt") as f:

for line in f:

key, val = line.split("\t")

if key in points:

points[key.strip()] += int(val)

point_list = sum_points(points.values())

addr_code = place_user['full'].encode("utf-8").split()从我的代码中,我得到了两个数据。首先是point_list。它是下面的数据列表类型。

[1.0]

[3.0]

[0.0]

[2.0]

[1.0]另一个是addr_code。这也是下面的数据列表类型。

['CA']

['NJ']

['DC']

['NJ']

['RI']这两个数据显示了这些信息。

'CA'= 1.0,'NJ'= 3.0,'DC'= 0.0,'NJ'= 2.0,'RI'= 1.0

从这些数据中,我想得到如下的简单结果。

NJ has the biggest point: 5.0如何编写代码获取结果的最后部分?请告诉我是否有错误的部分。

我会等你的帮助。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值