title: Is there a way to compute all the legit partitions of a set with Python?
body: <p>Wiki gives this <a href="https://en.wikipedia.org/wiki/Partition_of_a_set" rel="nofollow noreferrer">definition</a> of a partition of a set</p>
  
  <blockquote>
    <p>In mathematics, a partition of a set is a grouping of the set's elements into non-empty subsets, in such a way that every element is included in exactly one subset.</p>
  </blockquote>
  
  <p>And this example </p>
  
  <p>The set { 1, 2, 3 } has these five partitions</p>
  
  <pre><code>{ {1}, {2}, {3} }, sometimes written 1|2|3.
  { {1, 2}, {3} }, or 12|3.
  { {1, 3}, {2} }, or 13|2.
  { {1}, {2, 3} }, or 1|23.
  { {1, 2, 3} }, or 123
  </code></pre>
  
  <p>Is there a way to compute all the legit partitions of a set with Python?</p>
  
  <p>I've tried <a href="https://docs.sympy.org/latest/modules/combinatorics/partitions.html" rel="nofollow noreferrer">the partitions in sympy</a></p>
  
  <pre><code>from sympy.combinatorics.partitions import Partition
  a = Partition([1, 2, 3])
  a.members
  </code></pre>
  
  <p>and I got</p>
  
  <pre><code>(1, 2, 3)
  </code></pre>
  
  <p>which is apparently incorrect.</p>