New submission from Nathan Brooks <natebrooks...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue40109>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to