0
return dict(map(lambda (w, m): (w, float(m)), [wmsr.strip().split('\t')[0:2] for wmsr in open(f) ]))
^
SyntaxError: invalid syntax
return dict(map(lambda (w, m): (w, float(m)), [wmsr.strip().split('\t')[0:2] for wmsr in open(f) ]))
^
SyntaxError: invalid syntax
使用星图来代替:
from itertools import starmap
with open(f) as data:
return dict(starmap(lambda w, m: (w, float(m)), (wmsr.strip().split('\t')[:2] for wmsr in data)))
我完全认为'starmap'会被内置于疯狂的内部,用于绘制作为序列提供的空间中复杂的恒星地图内的所有对象之间的关系。它不是那样,但我认为如果一个人聪明,它会被用来做这样的事情。酷功能! – ThorSummoner 2015-04-04 08:52:38
[元组参数拆包(https://www.python.org/dev/peps/pep-3113/)是不可能在Python 3 – 2015-04-04 07:15:20