Skip to content

Instantly share code, notes, and snippets.

@meehow
Created April 22, 2011 11:53
Show Gist options
  • Save meehow/936511 to your computer and use it in GitHub Desktop.
Save meehow/936511 to your computer and use it in GitHub Desktop.
change values of two variables without third variable
#!/usr/bin/env python
import sys
def main(a, b):
print 'a = %d, b = %d' % (a, b)
b ^= a
a ^= b
b ^= a
print 'a = %d, b = %d' % (a, b)
if __name__ == '__main__':
main(int(sys.argv[1]), int(sys.argv[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment