2015-04-04 83 views
0
return dict(map(lambda (w, m): (w, float(m)), [wmsr.strip().split('\t')[0:2] for wmsr in open(f) ])) 
         ^
SyntaxError: invalid syntax 
+4

[元組參數拆包(https://www.python.org/dev/peps/pep-3113/)是不可能在Python 3 – 2015-04-04 07:15:20

回答

0

使用星圖來代替:

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))) 
+0

我完全認爲'starmap'會被內置於瘋狂的內部,用於繪製作爲序列提供的空間中複雜的恆星地圖內的所有對象之間的關係。它不是那樣,但我認爲如果一個人聰明,它會被用來做這樣的事情。酷功能! – ThorSummoner 2015-04-04 08:52:38

相關問題