moving items in a list

Skip Montanaro skip at pobox.com
Tue Jan 7 16:50:15 EST 2003


    ...
    Mark>         j = i - 1
    Mark>         swap_with = l[j]
    Mark>         l[i] = swap_with
    Mark>         l[j] = item
    ...

How about

    l[i-1], l[i] = l[i], l[i-1]

?  It's visually simpler than using a temporary variable and captures the
sentiment better I think.

Skip





More information about the Python-list mailing list