old_contents: import sys
  
  def swap(a, i, j):
      a[i], a[j] = a[j], a[i]
  
  def generatePermutations(n, a):
      if n == 0:
          print ''.join(a)
      else:
          for i in range(n+1):
              generatePermutations(n-1, a)
              swap(a, i if n % 2 == 0 else 0, n)
  
  if len(sys.argv) != 2:
      sys.stderr.write('Exactly one argument is required\n')
      sys.exit(1)
  word = sys.argv[1]
  generatePermutations(len(word)-1, list(word))
  
new_contents: import sys
  
  def generatePermutations(n, a):
      if n == 0:
          print(''.join(a))
      else:
          for i in range(n+1):
              generatePermutations(n-1, a)
              swap_index = i if n % 2 == 0 else 0
              a[swap_index], a[n] = a[n], a[swap_index]
  
  if len(sys.argv) != 2:
      sys.stderr.write('Exactly one argument is required\n')
      sys.exit(1)
  word = sys.argv[1]
  generatePermutations(len(word)-1, list(word))
  
subject: Simplify Python anagram script