2012-06-21 49 views
-1
missing_buckets = [x in timebuckets if ((x not in found_tenors) and (x == '1y' or x[-1] != 'y'))] 

語法錯誤我得到的錯誤:的Python:在列表理解語句

missing_buckets = [x in timebuckets if ((x not in found_tenors) and (x == '1y' or x[-1] != 'y'))] 
                           ^
SyntaxError: invalid syntax 
+2

哪裏錯誤? – kindall

+2

克拉不是錯誤。 – geoffspear

+0

我認爲你複製粘貼python語句兩次,而不是錯誤。 – Milimetric

回答

6
missing_buckets = [x for x in timebuckets if ((x not in found_tenors) and (x == '1y' or x[-1] != 'y'))] 
        ^^^^^ 
+0

我知道這會是一件愚蠢的事情。謝謝!。最近我在太多語言之間進行了交換。 –

3

你忘了 「關於x的」:

missing_buckets = [x for x in timebuckets if ((x not in found_tenors) and (x == '1y' or x[-1] != 'y'))]