title: Efficient way to generate all combinations of a list regardless of order
body: <p>I have the following code snippet that is quite inefficient: It aims to produce 27 different combinations of <strong>exactly</strong> <strong>3</strong> <strong>numbers</strong> for each combination</p>
  <pre><code>nums = [i for i in range(1,4)]
  combinations = []
  for i in nums:
    for j in nums:
      for k in nums:
        combinations.append([i,j,k])
  </code></pre>
  <p>This generates 27 combinations which is correct.</p>
  <p>Is there a more efficient way to generate this and how can I store into a dataframe instead of a list ?</p>