dictutils.pivotΒΆ

dictutils.pivot(d, order)[source]ΒΆ

Pivot a nested dictionary by rearranging the key levels according to order.

Parameters:
  • d (dict) – Input nested dictionary

  • order (list[int]) – List of indices specifying the new order of key levels

Return type:

dict

Returns:

Pivoted dictionary with keys rearranged

Example

d = {β€œA”: {β€œX”: 1, β€œY”: 2}, β€œB”: {β€œX”: 3, β€œY”: 4}} pivot(d, [1, 0]) -> {β€œX”: {β€œA”: 1, β€œB”: 3}, β€œY”: {β€œA”: 2, β€œB”: 4}}