Py学习  »  Python

` sorted()`occurs`syntaxError`在python3中

jason • 6 年前 • 1722 次点击  

我有以下代码,这些代码尝试用python3中的索引对列表进行排序:

myList = [1,3,4,5,6]
sorted((e,i) for i,e in enumerate(myList))

以上代码工作正常。但当我试图通过

sorted((e,i) for i,e in enumerate(myList),reverse=True)

我得到

SyntaxError: Generator expression must be parenthesized if not sole argument

这是怎么回事?谢谢

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39230
 
1722 次点击  
文章 [ 1 ]  |  最新文章 6 年前