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

我得到错误:

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

2 回答 2

6
missing_buckets = [x for x in timebuckets if ((x not in found_tenors) and (x == '1y' or  x[-1] != 'y'))]
                   ^^^^^
于 2012-06-21T14:02:09.107 回答
3

你忘记了“for x in”:

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

于 2012-06-21T14:04:19.213 回答