SyntaxError:Python内联for循环的语法无效

SyntaxError:Python内联for循环的语法无效,python,python-2.7,for-loop,Python,Python 2.7,For Loop,我有一个for循环来分配值,并用findtext的第一个值替换sentss2中的现有值。为此,我编写了一个for循环,它工作得非常完美: wordnum = [14, 1, 7, 0, 0, 11] sentNum = [4, 2, 8, 6, 5, 8] findtext = [u'I', u'our', u'it', u'The villa', u'It', u'the large main pool'] sentss2 = [ ['When', 'planning', 'our',

我有一个for循环来分配值,并用findtext的第一个值替换sentss2中的现有值。为此,我编写了一个for循环,它工作得非常完美:

wordnum = [14, 1, 7, 0, 0, 11]
sentNum = [4, 2, 8, 6, 5, 8]
findtext = [u'I', u'our', u'it', u'The villa', u'It', u'the large main pool']
sentss2 = [
    ['When', 'planning', 'our', 'return', 'trip', 'to', 'Kauai', ',', 'husband', 'and', 'I', 'were', 'happy', 'to', 'read', 'that', 'all', 'the', 'renovations', 'to', 'the', 'Koloa', 'Landing', 'Resort', 'were', 'completed', '.'],
    ['We', 'then', 'went', 'ahead', 'and', 'booked', 'a', 'deluxe', 'studio', 'for', 'mid-October', '.'],
    ['Upon', 'our', 'check', 'in', 'after', 'a', 'long', 'flight', 'and', 'dark', 'rainy', 'drive', 'from', 'the', 'airport', ',', 'we', 'were', 'greeted', 'warmly', 'at', 'the', 'front', 'desk', '.'],
    ['While', 'we', 'are', 'platinum', 'status', ',', 'we', 'were', "n't", 'expecting', 'a', 'room', 'upgrade', ',', 'but', 'much', 'to', 'our', 'delight', ',', 'was', 'advised', 'by', 'the', 'clerk', 'that', 'we', 'received', 'one', '.'],
    ['However', ',', 'it', 'was', "n't", 'until', 'we', 'got', 'to', 'our', 'room', ',', 'or', 'should', 'I', 'say', 'villa', ',', 'how', 'nice', 'the', 'upgrade', 'was', '.'],
    ['It', 'was', 'a', 'one', 'bedroom', ',', '1', '1/2', 'bath', ',', 'almost', '1000', 'square', 'feet', 'corner', 'villa', 'with', '2', 'full', 'walls', 'of', 'windows', 'in', 'the', 'lovely', 'living', 'room', 'alone', '.'],
    ['The', 'villa', 'was', 'beautiful', '.'],
    ['Our', 'view', 'of', 'the', 'smaller', 'family', 'pool', 'and', 'soccer', 'field', 'was', 'so', 'nice', '.'],
    ['Really', 'enjoyed', 'being', 'in', 'this', 'area', 'as', 'it', "'s", 'quieter', 'than', 'the', 'large', 'main', 'pool', '.']
]
现在我想在一个内联语句中编写它,以更快地执行这个耗时的循环。如果我像下面这样编写内联循环:

for aa,bb,cc in zip(sentNum,findtext,wordnum):
    sentss2[aa][cc]=findtext[0].lower()
我得到一个无效的语法错误:

[(sentss2[aa][cc]=findtext[0],findtext[0].lower())[0] for aa,cc in zip(sentNum,wordnum)]

如何编写此内联for循环有任何帮助吗?

您不能在列表中分配

无论如何,[…for…]列表理解并不比常规for循环快。无论是在一行还是两行上,这都是一个for循环。两行版本的优点是在语法上有效


坚持原来的循环。

列表理解并不比常规for循环快,我不同意。你对这个问题有什么看法?它说列表理解比。。。什么仔细阅读。
 File "<ipython-input-142-82f373e08c0a>", line 1
    [(sentss2[aa][cc]=findtext[0],findtext[0].lower())[0] for aa,cc in zip(sentNum,wordnum)]
                     ^
SyntaxError: invalid syntax