title: Backtracking permuting a list
body: <p>I am trying to permute a list but I cannot do it, it goes infinite cycle. I tried different things but somehow the only thing that it shows me is 1 2 3 ... 1 2 3 etc</p>
  
  <p>This is the code:</p>
  
  <pre><code>def prints(v,k):
      s = ''
      for i in range(k + 1):
          s += str(v[i]) + ' '
      print(s)   
  
  def continuare(v,k):
      ok = True
      for i in range(k):
          if v[i] == v[k]:
              ok = False
              break
      return ok
  
  def back(v,a):
      k = 0
      caut = False
      while k&gt;-1:
          caut = False        
          pos = 0
          while pos &lt; len(a) and caut == False:
                  v[k] = a[pos]
                  pos += 1
                  if continuare(v,k):
                      caut = True
          if caut == False:
              k -= 1
          elif k == len(a) - 1:
              prints(v,k)
          else:
              k += 1
  
  
  a = [1,2,3]
  v = []
  for x in range(len(a)):
      v.append(a[0])
  back(v,a)
  </code></pre>