No built-in swap function?

Andrew Koenig ark at acm.org
Mon Mar 29 12:12:42 EST 2004


I am looking for the most effective way to exchange v[i] and v[j], and
expected to find something like

    v.swap(i, j)

but it doesn't seem to exist.  Is there anything better than

    v[i], v[j] = v[j], v[i]

(which I don't like particularly because it evaluates each of v[i] and v[j]
twice)?





More information about the Python-list mailing list