title: Speed up for loop in python
body: <p>I have a code snippet that generates a list of vectors for a optimization problem, but it takes to long time to run.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import numpy as np
  import itertools as it
  import time
  
  v=[35,36,37,38,39,40,41,42,43,44,45,46]
  
  
  m=np.array(list(it.combinations_with_replacement(v,9)))
  g=m[np.sum(m, axis=1)==360]
  print('g shape',g.shape)
  
  f=[]
  for i,vector in enumerate(g[0:10]): #all vector is to be processed, but it takes tolong time
      print(i)
      start = time.time()
      unique_permutations = set(it.permutations(vector))
      end = time.time()
      print('length unique perm',len(unique_permutations))
      print('time perm',end-start)
  
      already_reviewed = []
  
      start= time.time()
      for p in list(unique_permutations):
          if p not in already_reviewed:       # a lot of time is spen in this check
              circular_permutations = [p[i:] + p[:i] for i in range(len(p))]
              already_reviewed.extend(circular_permutations)
              unique_permutations.difference_update(circular_permutations[1:])
      end=time.time()
      print('loop', end-start)       
  
      f.append(list(unique_permutations))
  </code></pre>
  
  <p>Would really much appreciate help.
  Br Erik</p>