Python:列表理解语句中的语法错误

2024-10-02 10:33:05 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Tags: orandinif错误notsyntaxmissing
2条回答

你忘了“为x在”:

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

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

相关问题 更多 >

    热门问题