Python 2.6生成器表达式如果不是唯一的参数,则必须加括号

Python 2.6生成器表达式如果不是唯一的参数,则必须加括号,python,python-2.6,Python,Python 2.6,我为Python2.6重写了以下Python2.7+代码 Python 2.7+ options = {key: value for key, value in options.items() if value is not None} Python 2.6 options = dict((key, value) for key, value in options.items() if value is not None) 但是我得到了以下错误 SyntaxError: Generator

我为Python2.6重写了以下Python2.7+代码

Python 2.7+

options = {key: value for key, value in options.items() if value is not None}
Python 2.6

options = dict((key, value) for key, value in options.items() if value is not None)
但是我得到了以下错误

SyntaxError: Generator expression must be parenthesized if not sole argument

我做错了什么?

我认为这应该奏效。当您实际尝试运行此代码时,是否确实按照您向我们展示的方式插入了所有内容?(另外,不要在Python中使用Javascript/HTML/CSS snippet按钮。另外,eugh,Python 2.6?)无法在2.6.9上复制。我完全复制了代码。我使用的是Python 2.6.6,无法在2.6.6中复制,甚至无法在2.5.6中复制;当您仍在使用RHEL6服务器时,这就是您所使用的。阿非斯,它应该起作用。你有没有试着把它转换成一个列表?dict([…])