Partitions of an integer
ml at dynkin.com
Sat Jul 24 18:50:44 CEST 2004
Nick J Chackowsky wrote:
> Wrote a python script to find the partitions of an integer (a list of
> all the ways you can express n as a sum of integers). For example, the
> partitions of 5 are
> My method, however, generates plenty of duplicates (note the if
> statement to catch them). Generating the 15 partitions of 7, for
> example, also generates 19 duplicates. Can someone spot a way to improve
> or eliminate the duplicates?
You should check this recipe:
Generator for integer partitions
This is a cool example of how to use generators with recursion.
More information about the Python-list