def combined_cuboids(dimensions, required=None):
 required = (tuple(required) if required else ())
 for dim in required:
  if (dim not in dimensions):
   raise ArgumentError(("Required dimension '%s' is not in list of dimensions to be combined." % str(dim)))
 cuboids = []
 to_combine = [dim for dim in dimensions if (not (dim in required))]
 for i in range(len(to_combine), 0, (-1)):
  combos = itertools.combinations(to_combine, i)
  combos = [(required + combo) for combo in combos]
  cuboids += tuple(combos)
 if required:
  cuboids = ([required] + cuboids)
 return cuboids

def combined_cuboids ( dimensions , required = None ) : required = ( tuple ( required ) if required else ( ) ) for dim in required : if ( dim not in dimensions ) : raise ArgumentError ( ( "Required dimension '%s' is not in list of dimensions to be combined." % str ( dim ) ) ) cuboids = [ ] to_combine = [ dim for dim in dimensions if ( not ( dim in required ) ) ] for i in range ( len ( to_combine ) , 0 , ( - 1 ) ) : combos = itertools . combinations ( to_combine , i ) combos = [ ( required + combo ) for combo in combos ] cuboids += tuple ( combos ) if required : cuboids = ( [ required ] + cuboids ) return cuboids
returns a list of all combinations of dimensions as tuples .