[issue40109] List index doesn't work with multiple assignment

Nathan Brooks report at bugs.python.org
Sun Mar 29 21:22:35 EDT 2020


New submission from Nathan Brooks <natebrooks004 at gmail.com>:

Faulty example:
x = [1,2,3,4,5,6,7]
# this should replace items 3 and 6 with each other
x[2], x[x.index(6)] = 6, x[2]
print(x)
[1,2,3,4,5,6,7]

Workaround:
x = [1,2,3,4,5,6,7]
i = x.index(6)
# this replaces items 3 and 6 in the list.
x[2], x[i] = 6, x[2]
print(x)
[1,2,6,4,5,3,7]

----------
messages: 365289
nosy: Nathan Brooks
priority: normal
severity: normal
status: open
title: List index doesn't work with multiple assignment

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40109>
_______________________________________


More information about the Python-bugs-list mailing list