#!/usr/bin/env python

def partition(a, l, r, n):
    # array, left bound, right bound, number of partitions

    if n == 1:
        result = [[l, r]]
        yield result

    for i in xrange(l, r - 1):
        x = [[l, i+1]]
        for p in partition(a, i + 1, r, n - 1):
            result = x + p
            yield result

a = [1,7,2,4,6,1,8,0,9]

for p in partition(a, 0, len(a), 1):
    print p

for p in partition(a, 0, len(a), 2):
    print p


