python - Hadoop 的 Python 3 不支持子列表参数
问题描述
我在为 (lambda (x, (y, z)) 解决此问题时遇到问题:[(dest, z/len(y))
Python 3.xPylance 中不支持错误消息子列表参数
仅位置参数分隔符不允许作为第一个参数
print "Run 30 Iterations"
for i in range(1, 30):
print "Number of Iterations"
print i
JoinRDD = AdjList3.join(PageRankValues)
print "join results"
print JoinRDD.collect()
contributions = JoinRDD.flatMap(lambda (x, (y, z)) : [(dest, z/len(y)) for dest in y]) # 4. Replace the lambda function with yours
print "contributions"
print contributions.collect()
accumulations = contributions.reduceByKey(lambda x, y : x + y) # 5. Replace the lambda function with yours
print "accumulations"
print accumulations.collect()
PageRankValues = accumulations.mapValues(lambda v : 0.85 * v + 0.15 / float(nNumOfNodes)) # 6. Replace the lambda function with yours
print "PageRankValues"
print PageRankValues.collect()
解决方案
Python 3 不支持(x, (y,z))
where(y,z)
将是 sublist 参数。
您可以将此行重写为
contributions = JoinRDD.flatMap(lambda x, yz : [(dest, yz[1]/len(yz[0])) for dest in yz[0]])
让我知道这是否适合您。
推荐阅读
- c# - 如何将流从 Delphi 传递到 C#?
- php - 在 PhpStorm 中为对象获取 Smarty 中的代码完成
- kibana - 无法验证第一个证书 - kibana/elasticsearch
- python-3.x - Python 3 生成器表达式
- javascript - 如何禁用滚动
- c - 在 C 代码中对未排序文本文件的输出进行排序
- python - 在python中对一列求和
- python - 在python中查找两个数组的交集
- angular - 定位 cdk 覆盖时出错
- javascript - 无法使用视频控件播放来自 iframe 页面的 youtube 嵌入视频 iframe 是 youtube 视频的页面