title: Python: Merge Sort in ascending and descending order
body: <p>I'm trying to implement merge sort in Python that sorts either in ascending or in descending order depending on the parameter you give it. I got it working with 2 separate functions but I can't get it to work in one function.</p>
  
  <pre><code>def mergeSort(L, ascending = True):
      print('Mergesort, Parameter L:')
      print(L)
      result = []  
      if len(L) == 1:
          return L  
      mid = len(L) // 2  
      teilliste1 = mergeSort(L[:mid], ascending)  
      teilliste2 = mergeSort(L[mid:], ascending)  
      x, y = 0, 0
      while x &lt; len(teilliste1) and y &lt; len(teilliste2):
          if ascending:
              if teilliste1[x] &gt; teilliste2[y]:
                  result.append(teilliste2[y])
                  y = y + 1
              else:
                  result.append(teilliste1[x])
                  x = x + 1
          else: 
              if teilliste1[x] &lt; teilliste2[y]:
                  result.append(teilliste2[y])
                  y = y + 1
              else:
                  result.append(teilliste1[x])
                  x = x + 1
      result = result + teilliste1[x:]
      result = result + teilliste2[y:]
      return result
  
  mergeSort(list, True) # sort in ascending order
  mergeSort(list, False) # sort in descending order
  </code></pre>
  
  <p>Just flipping the > in the if-statement will make it descending but if I try doing both in one function, it always messes up my result. Any suggestions?</p>