Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 6, 2014 20:18
Show Gist options
  • Save globby/9398749 to your computer and use it in GitHub Desktop.
Save globby/9398749 to your computer and use it in GitHub Desktop.
The in-place xor swap algorithm
def swap(lst,a,b):
lst[a] = lst[a] ^ lst[b]
lst[b] = lst[a] ^ lst[b]
lst[a] = lst[a] ^ lst[b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment