0

Given a string like xyz i would like to generate the partition of a set. NOT a power set but only pairings one can construct the original string from (see example below).

def get_pairings(a_string):
    # return a list of lists where each list contains 
    # lists that together contain all the characters of a_string

Example

Given the string xyz, the function get_pairings shall return:

[
 [['x'], ['y'], ['z']], 
 [['z'], ['x', 'y']], 
 [['x'], ['y', 'z']], 
 [['y'], ['x', 'z']],
 [['x', 'y', 'z']]
]

Given the string xy, the result would be:

[
 [['x'], ['y']],
 [['x', 'y']]
]

How is this possible in python?

Thanks for your help!

0 Answers0