title: A combination algorithm in python
body: <pre><code>import copy
  
  def combine(l, n):
      answers = []
      one = [0] * n
      def next_c(li = 0, ni = 0):
          if ni == n:
              answers.append(copy.copy(one))
              return
          for k in range(li, len(l)):
              one[ni] = l[k]
              next_c(k+1, ni+1)
      next_c()
      return answers
  
  print(combine([1,2,3,4],2)) 
  </code></pre>
  
  <p>Recently I found this code on internet. It works very well. However, I do not know the details that how does it work？ So can anybody tell me how does it work? And how to understand a recursive code quickly? Thanks very much</p>