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如何编写代码获取结果的最后部分?请告诉我是否有错误的部分。
我会等你的帮助。