title: Itertools permutations with replacement one by one
body: <p>I am trying to generate all permutations with replacement using itertools, but data is too big for RAM, so my computer goes down. </p>
  
  <p>There are too many tuples, can i generate them one by one and add to file without creating all the list? Here is my code</p>
  
  <pre><code>from itertools import product
  k = 4
  n = 2
  f = open('vectors.txt', 'w')
  //func_val = list(product(range(k), repeat=k ** n))
  for i in list(product(range(k), repeat=k ** n)):
      f.write(str(i) + '\n')
  </code></pre>