list2tree


Namelist2tree JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/list2tree
SummaryConverts a list of tuples to a nested "family tree dict
upload_time2023-04-20 04:27:25
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords tree list recursive dict convert family tree
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Converts a list of tuples to a nested "family tree dict"  

## pip install list2tree


#### Tested against Windows 10 / Python 3.10 / Anaconda


```python
from list2tree import treedict,edit_value_in_treedict,get_value_in_treedict
import pprint as pa
pprintx=pa.PrettyPrinter(indent=1,width=1,compact=True)
pprint=pprintx.pprint
nameconnections = [
    ("Maria", "Anna"),
    ("Anna", "Joao"),
    ("Kasimir", "Maria"),
    ("Hans", "Fritz"),
    ("Fritz", "Anna"),
    ("Günther", "Wolfgang"),
    ("Joao", "Wolfgang"),
]
print("0) --------------------------------------------------------------")
mapped, airvar = treedict(
    pairs_list=nameconnections, main_mapping_keys=(), bi_rl_lr="lr"
)
pprint(mapped)
pprint(airvar)
print("1) --------------------------------------------------------------")
mapped, airvar = treedict(
    pairs_list=nameconnections, main_mapping_keys=(), bi_rl_lr="rl"
)
pprint(mapped)
pprint(airvar)
print("2) --------------------------------------------------------------")
mapped, airvar = treedict(
    pairs_list=nameconnections, main_mapping_keys=(), bi_rl_lr="bi"
)
pprint(mapped)
pprint(airvar)
print("3) --------------------------------------------------------------")
mapped, airvar = treedict(
    pairs_list=nameconnections, main_mapping_keys=("Anna", "Günther"), bi_rl_lr="lr"
)
pprint(mapped)
pprint(airvar)
print("4) --------------------------------------------------------------")
mapped, airvar = treedict(
    pairs_list=nameconnections, main_mapping_keys=("Anna", "Wolfgang"), bi_rl_lr="rl"
)
pprint(mapped)
pprint(airvar)
print("5) --------------------------------------------------------------")
mapped, airvar = treedict(
    pairs_list=nameconnections, main_mapping_keys=("Anna",), bi_rl_lr="bi"
)
pprint(mapped)
pprint(airvar)
print("6) --------------------------------------------------------------")
v1 = get_value_in_treedict(airvar, ("Anna", "Joao", "Wolfgang", "Günther"))
print(v1)
edit_value_in_treedict(
    airvar, ("Anna", "Joao", "Wolfgang", "Günther"), "new_value_edit"
)
pprint(airvar)
v2 = get_value_in_treedict(airvar, ("Anna", "Joao", "Wolfgang", "Günther"))
print(v2)
print("7) --------------------------------------------------------------")
0) --------------------------------------------------------------
[(1,
  ('Wolfgang',)),
 (2,
  ('Günther',
   'Wolfgang')),
 (3,
  ('Joao',
   'Wolfgang')),
 (4,
  ('Anna',
   'Joao',
   'Wolfgang')),
 (5,
  ('Fritz',
   'Anna',
   'Joao',
   'Wolfgang')),
 (6,
  ('Maria',
   'Anna',
   'Joao',
   'Wolfgang')),
 (7,
  ('Hans',
   'Fritz',
   'Anna',
   'Joao',
   'Wolfgang')),
 (8,
  ('Kasimir',
   'Maria',
   'Anna',
   'Joao',
   'Wolfgang'))]
{'Anna': {'Joao': {'Wolfgang': 4}},
 'Fritz': {'Anna': {'Joao': {'Wolfgang': 5}}},
 'Günther': {'Wolfgang': 2},
 'Hans': {'Fritz': {'Anna': {'Joao': {'Wolfgang': 7}}}},
 'Joao': {'Wolfgang': 3},
 'Kasimir': {'Maria': {'Anna': {'Joao': {'Wolfgang': 8}}}},
 'Maria': {'Anna': {'Joao': {'Wolfgang': 6}}},
 'Wolfgang': 1}
1) --------------------------------------------------------------
[(1,
  ('Günther',)),
 (2,
  ('Hans',)),
 (3,
  ('Kasimir',)),
 (4,
  ('Fritz',
   'Hans')),
 (5,
  ('Maria',
   'Kasimir')),
 (6,
  ('Wolfgang',
   'Günther')),
 (7,
  ('Wolfgang',
   'Joao',
   'Anna',
   'Maria',
   'Kasimir')),
 (8,
  ('Wolfgang',
   'Joao',
   'Anna',
   'Fritz',
   'Hans')),
 (9,
  ('Anna',
   'Maria',
   'Kasimir')),
 (10,
  ('Anna',
   'Fritz',
   'Hans')),
 (11,
  ('Joao',
   'Anna',
   'Maria',
   'Kasimir')),
 (12,
  ('Joao',
   'Anna',
   'Fritz',
   'Hans'))]
{'Anna': {'Fritz': {'Hans': 10},
          'Maria': {'Kasimir': 9}},
 'Fritz': {'Hans': 4},
 'Günther': 1,
 'Hans': 2,
 'Joao': {'Anna': {'Fritz': {'Hans': 12},
                   'Maria': {'Kasimir': 11}}},
 'Kasimir': 3,
 'Maria': {'Kasimir': 5},
 'Wolfgang': {'Günther': 6,
              'Joao': {'Anna': {'Fritz': {'Hans': 8},
                                'Maria': {'Kasimir': 7}}}}}
2) --------------------------------------------------------------
[(1,
  ('Anna',
   'Joao',
   'Wolfgang',
   'Günther')),
 (2,
  ('Anna',
   'Maria',
   'Kasimir')),
 (3,
  ('Anna',
   'Fritz',
   'Hans')),
 (4,
  ('Fritz',
   'Anna',
   'Joao',
   'Wolfgang',
   'Günther')),
 (5,
  ('Fritz',
   'Anna',
   'Maria',
   'Kasimir')),
 (6,
  ('Fritz',
   'Hans')),
 (7,
  ('Günther',
   'Wolfgang',
   'Joao',
   'Anna',
   'Maria',
   'Kasimir')),
 (8,
  ('Günther',
   'Wolfgang',
   'Joao',
   'Anna',
   'Fritz',
   'Hans')),
 (9,
  ('Hans',
   'Fritz',
   'Anna',
   'Joao',
   'Wolfgang',
   'Günther')),
 (10,
  ('Hans',
   'Fritz',
   'Anna',
   'Maria',
   'Kasimir')),
 (11,
  ('Joao',
   'Wolfgang',
   'Günther')),
 (12,
  ('Joao',
   'Anna',
   'Maria',
   'Kasimir')),
 (13,
  ('Joao',
   'Anna',
   'Fritz',
   'Hans')),
 (14,
  ('Kasimir',
   'Maria',
   'Anna',
   'Joao',
   'Wolfgang',
   'Günther')),
 (15,
  ('Kasimir',
   'Maria',
   'Anna',
   'Fritz',
   'Hans')),
 (16,
  ('Maria',
   'Anna',
   'Joao',
   'Wolfgang',
   'Günther')),
 (17,
  ('Maria',
   'Anna',
   'Fritz',
   'Hans')),
 (18,
  ('Maria',
   'Kasimir')),
 (19,
  ('Wolfgang',
   'Günther')),
 (20,
  ('Wolfgang',
   'Joao',
   'Anna',
   'Maria',
   'Kasimir')),
 (21,
  ('Wolfgang',
   'Joao',
   'Anna',
   'Fritz',
   'Hans'))]
{'Anna': {'Fritz': {'Hans': 3},
          'Joao': {'Wolfgang': {'Günther': 1}},
          'Maria': {'Kasimir': 2}},
 'Fritz': {'Anna': {'Joao': {'Wolfgang': {'Günther': 4}},
                    'Maria': {'Kasimir': 5}},
           'Hans': 6},
 'Günther': {'Wolfgang': {'Joao': {'Anna': {'Fritz': {'Hans': 8},
                                            'Maria': {'Kasimir': 7}}}}},
 'Hans': {'Fritz': {'Anna': {'Joao': {'Wolfgang': {'Günther': 9}},
                             'Maria': {'Kasimir': 10}}}},
 'Joao': {'Anna': {'Fritz': {'Hans': 13},
                   'Maria': {'Kasimir': 12}},
          'Wolfgang': {'Günther': 11}},
 'Kasimir': {'Maria': {'Anna': {'Fritz': {'Hans': 15},
                                'Joao': {'Wolfgang': {'Günther': 14}}}}},
 'Maria': {'Anna': {'Fritz': {'Hans': 17},
                    'Joao': {'Wolfgang': {'Günther': 16}}},
           'Kasimir': 18},
 'Wolfgang': {'Günther': 19,
              'Joao': {'Anna': {'Fritz': {'Hans': 21},
                                'Maria': {'Kasimir': 20}}}}}
3) --------------------------------------------------------------
[(1,
  ('Günther',
   'Wolfgang')),
 (2,
  ('Anna',
   'Joao',
   'Wolfgang'))]
{'Anna': {'Joao': {'Wolfgang': 2}},
 'Günther': {'Wolfgang': 1}}
4) --------------------------------------------------------------
[(1,
  ('Wolfgang',
   'Günther')),
 (2,
  ('Wolfgang',
   'Joao',
   'Anna',
   'Maria',
   'Kasimir')),
 (3,
  ('Wolfgang',
   'Joao',
   'Anna',
   'Fritz',
   'Hans')),
 (4,
  ('Anna',
   'Maria',
   'Kasimir')),
 (5,
  ('Anna',
   'Fritz',
   'Hans'))]
{'Anna': {'Fritz': {'Hans': 5},
          'Maria': {'Kasimir': 4}},
 'Wolfgang': {'Günther': 1,
              'Joao': {'Anna': {'Fritz': {'Hans': 3},
                                'Maria': {'Kasimir': 2}}}}}
5) --------------------------------------------------------------
[(1,
  ('Anna',
   'Joao',
   'Wolfgang',
   'Günther')),
 (2,
  ('Anna',
   'Maria',
   'Kasimir')),
 (3,
  ('Anna',
   'Fritz',
   'Hans'))]
{'Anna': {'Fritz': {'Hans': 3},
          'Joao': {'Wolfgang': {'Günther': 1}},
          'Maria': {'Kasimir': 2}}}
6) --------------------------------------------------------------
1
{'Anna': {'Fritz': {'Hans': 3},
          'Joao': {'Wolfgang': {'Günther': 'new_value_edit'}},
          'Maria': {'Kasimir': 2}}}
new_value_edit
7) --------------------------------------------------------------




treedict(
    pairs_list: list | tuple, main_mapping_keys: tuple | list = (), bi_rl_lr: str = "lr"
):
    """
    This function takes a list or tuple of pairs, a tuple or list of main mapping keys, and a string indicating the type
    of bidirectional mapping to be used. It returns a tuple of flattened dictionary and a nested dictionary.

    :param pairs_list: A list or tuple of pairs.
    :type pairs_list: list | tuple
    :param main_mapping_keys: A tuple or list of main mapping keys.
    :type main_mapping_keys: tuple | list
    :param bi_rl_lr: A string indicating the type of bidirectional mapping to be used. Default is "lr", Valid options are
                     lr - left to right / rl - right to left / bi - bidirectional
    :type bi_rl_lr: str
    :return: A tuple of flattened dictionary and a nested dictionary.
    :rtype: tuple
    """
	
edit_value_in_treedict(d: dict, keys: list | tuple, newvalue: Any) -> None:
    """
    Edit the value of a nested dictionary given a list of keys.

    Args:
        d (dict): The nested dictionary to be edited.
        keys (list,tuple): A list of keys representing the path to the value to be edited.
        newvalue (Any): The new value to be assigned to the specified key path.

    Returns:
        None: This function does not return anything, but it changes the ORIGINAL dict! If you want to keep a copy of
        the original dict, use copy.deepcopy(d) before you call the function

    Raises:
        KeyError: If any of the keys in the list do not exist in the dictionary.

    Example:
        d = {'a': {'b': {'c': 1}}}
        keys = ['a', 'b', 'c']
        newvalue = 2
        edit_value_in_treedict(d, keys, newvalue)
        # d is now {'a': {'b': {'c': 2}}}
    """	
	
	
get_value_in_treedict(d: dict, keys: list | tuple) -> Any:
    """
    Returns the value in a nested dictionary `d` at the specified `keys`.

    Args:
        d (dict): The nested dictionary to search for the value.
        keys (list|tuple): The list or tuple of keys to traverse the nested dictionary.

    Returns:
        Any: The value at the specified `keys` in the nested dictionary `d`.

    Raises:
        TypeError: If `d` is not a dictionary or `keys` is not a list or tuple.
        KeyError: If any of the keys in `keys` do not exist in the nested dictionary `d`.
    """
	
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/list2tree",
    "name": "list2tree",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "tree,list,recursive,dict,convert,family tree",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/58/43/5bad03e51c36cd0a5140eff13c2c3595d3ad11bdff5ba7b4fe39b5e5c748/list2tree-0.10.tar.gz",
    "platform": null,
    "description": "# Converts a list of tuples to a nested \"family tree dict\"  \r\n\r\n## pip install list2tree\r\n\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda\r\n\r\n\r\n```python\r\nfrom list2tree import treedict,edit_value_in_treedict,get_value_in_treedict\r\nimport pprint as pa\r\npprintx=pa.PrettyPrinter(indent=1,width=1,compact=True)\r\npprint=pprintx.pprint\r\nnameconnections = [\r\n    (\"Maria\", \"Anna\"),\r\n    (\"Anna\", \"Joao\"),\r\n    (\"Kasimir\", \"Maria\"),\r\n    (\"Hans\", \"Fritz\"),\r\n    (\"Fritz\", \"Anna\"),\r\n    (\"G\u00c3\u00bcnther\", \"Wolfgang\"),\r\n    (\"Joao\", \"Wolfgang\"),\r\n]\r\nprint(\"0) --------------------------------------------------------------\")\r\nmapped, airvar = treedict(\r\n    pairs_list=nameconnections, main_mapping_keys=(), bi_rl_lr=\"lr\"\r\n)\r\npprint(mapped)\r\npprint(airvar)\r\nprint(\"1) --------------------------------------------------------------\")\r\nmapped, airvar = treedict(\r\n    pairs_list=nameconnections, main_mapping_keys=(), bi_rl_lr=\"rl\"\r\n)\r\npprint(mapped)\r\npprint(airvar)\r\nprint(\"2) --------------------------------------------------------------\")\r\nmapped, airvar = treedict(\r\n    pairs_list=nameconnections, main_mapping_keys=(), bi_rl_lr=\"bi\"\r\n)\r\npprint(mapped)\r\npprint(airvar)\r\nprint(\"3) --------------------------------------------------------------\")\r\nmapped, airvar = treedict(\r\n    pairs_list=nameconnections, main_mapping_keys=(\"Anna\", \"G\u00c3\u00bcnther\"), bi_rl_lr=\"lr\"\r\n)\r\npprint(mapped)\r\npprint(airvar)\r\nprint(\"4) --------------------------------------------------------------\")\r\nmapped, airvar = treedict(\r\n    pairs_list=nameconnections, main_mapping_keys=(\"Anna\", \"Wolfgang\"), bi_rl_lr=\"rl\"\r\n)\r\npprint(mapped)\r\npprint(airvar)\r\nprint(\"5) --------------------------------------------------------------\")\r\nmapped, airvar = treedict(\r\n    pairs_list=nameconnections, main_mapping_keys=(\"Anna\",), bi_rl_lr=\"bi\"\r\n)\r\npprint(mapped)\r\npprint(airvar)\r\nprint(\"6) --------------------------------------------------------------\")\r\nv1 = get_value_in_treedict(airvar, (\"Anna\", \"Joao\", \"Wolfgang\", \"G\u00c3\u00bcnther\"))\r\nprint(v1)\r\nedit_value_in_treedict(\r\n    airvar, (\"Anna\", \"Joao\", \"Wolfgang\", \"G\u00c3\u00bcnther\"), \"new_value_edit\"\r\n)\r\npprint(airvar)\r\nv2 = get_value_in_treedict(airvar, (\"Anna\", \"Joao\", \"Wolfgang\", \"G\u00c3\u00bcnther\"))\r\nprint(v2)\r\nprint(\"7) --------------------------------------------------------------\")\r\n0) --------------------------------------------------------------\r\n[(1,\r\n  ('Wolfgang',)),\r\n (2,\r\n  ('G\u00c3\u00bcnther',\r\n   'Wolfgang')),\r\n (3,\r\n  ('Joao',\r\n   'Wolfgang')),\r\n (4,\r\n  ('Anna',\r\n   'Joao',\r\n   'Wolfgang')),\r\n (5,\r\n  ('Fritz',\r\n   'Anna',\r\n   'Joao',\r\n   'Wolfgang')),\r\n (6,\r\n  ('Maria',\r\n   'Anna',\r\n   'Joao',\r\n   'Wolfgang')),\r\n (7,\r\n  ('Hans',\r\n   'Fritz',\r\n   'Anna',\r\n   'Joao',\r\n   'Wolfgang')),\r\n (8,\r\n  ('Kasimir',\r\n   'Maria',\r\n   'Anna',\r\n   'Joao',\r\n   'Wolfgang'))]\r\n{'Anna': {'Joao': {'Wolfgang': 4}},\r\n 'Fritz': {'Anna': {'Joao': {'Wolfgang': 5}}},\r\n 'G\u00c3\u00bcnther': {'Wolfgang': 2},\r\n 'Hans': {'Fritz': {'Anna': {'Joao': {'Wolfgang': 7}}}},\r\n 'Joao': {'Wolfgang': 3},\r\n 'Kasimir': {'Maria': {'Anna': {'Joao': {'Wolfgang': 8}}}},\r\n 'Maria': {'Anna': {'Joao': {'Wolfgang': 6}}},\r\n 'Wolfgang': 1}\r\n1) --------------------------------------------------------------\r\n[(1,\r\n  ('G\u00c3\u00bcnther',)),\r\n (2,\r\n  ('Hans',)),\r\n (3,\r\n  ('Kasimir',)),\r\n (4,\r\n  ('Fritz',\r\n   'Hans')),\r\n (5,\r\n  ('Maria',\r\n   'Kasimir')),\r\n (6,\r\n  ('Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (7,\r\n  ('Wolfgang',\r\n   'Joao',\r\n   'Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (8,\r\n  ('Wolfgang',\r\n   'Joao',\r\n   'Anna',\r\n   'Fritz',\r\n   'Hans')),\r\n (9,\r\n  ('Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (10,\r\n  ('Anna',\r\n   'Fritz',\r\n   'Hans')),\r\n (11,\r\n  ('Joao',\r\n   'Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (12,\r\n  ('Joao',\r\n   'Anna',\r\n   'Fritz',\r\n   'Hans'))]\r\n{'Anna': {'Fritz': {'Hans': 10},\r\n          'Maria': {'Kasimir': 9}},\r\n 'Fritz': {'Hans': 4},\r\n 'G\u00c3\u00bcnther': 1,\r\n 'Hans': 2,\r\n 'Joao': {'Anna': {'Fritz': {'Hans': 12},\r\n                   'Maria': {'Kasimir': 11}}},\r\n 'Kasimir': 3,\r\n 'Maria': {'Kasimir': 5},\r\n 'Wolfgang': {'G\u00c3\u00bcnther': 6,\r\n              'Joao': {'Anna': {'Fritz': {'Hans': 8},\r\n                                'Maria': {'Kasimir': 7}}}}}\r\n2) --------------------------------------------------------------\r\n[(1,\r\n  ('Anna',\r\n   'Joao',\r\n   'Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (2,\r\n  ('Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (3,\r\n  ('Anna',\r\n   'Fritz',\r\n   'Hans')),\r\n (4,\r\n  ('Fritz',\r\n   'Anna',\r\n   'Joao',\r\n   'Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (5,\r\n  ('Fritz',\r\n   'Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (6,\r\n  ('Fritz',\r\n   'Hans')),\r\n (7,\r\n  ('G\u00c3\u00bcnther',\r\n   'Wolfgang',\r\n   'Joao',\r\n   'Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (8,\r\n  ('G\u00c3\u00bcnther',\r\n   'Wolfgang',\r\n   'Joao',\r\n   'Anna',\r\n   'Fritz',\r\n   'Hans')),\r\n (9,\r\n  ('Hans',\r\n   'Fritz',\r\n   'Anna',\r\n   'Joao',\r\n   'Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (10,\r\n  ('Hans',\r\n   'Fritz',\r\n   'Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (11,\r\n  ('Joao',\r\n   'Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (12,\r\n  ('Joao',\r\n   'Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (13,\r\n  ('Joao',\r\n   'Anna',\r\n   'Fritz',\r\n   'Hans')),\r\n (14,\r\n  ('Kasimir',\r\n   'Maria',\r\n   'Anna',\r\n   'Joao',\r\n   'Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (15,\r\n  ('Kasimir',\r\n   'Maria',\r\n   'Anna',\r\n   'Fritz',\r\n   'Hans')),\r\n (16,\r\n  ('Maria',\r\n   'Anna',\r\n   'Joao',\r\n   'Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (17,\r\n  ('Maria',\r\n   'Anna',\r\n   'Fritz',\r\n   'Hans')),\r\n (18,\r\n  ('Maria',\r\n   'Kasimir')),\r\n (19,\r\n  ('Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (20,\r\n  ('Wolfgang',\r\n   'Joao',\r\n   'Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (21,\r\n  ('Wolfgang',\r\n   'Joao',\r\n   'Anna',\r\n   'Fritz',\r\n   'Hans'))]\r\n{'Anna': {'Fritz': {'Hans': 3},\r\n          'Joao': {'Wolfgang': {'G\u00c3\u00bcnther': 1}},\r\n          'Maria': {'Kasimir': 2}},\r\n 'Fritz': {'Anna': {'Joao': {'Wolfgang': {'G\u00c3\u00bcnther': 4}},\r\n                    'Maria': {'Kasimir': 5}},\r\n           'Hans': 6},\r\n 'G\u00c3\u00bcnther': {'Wolfgang': {'Joao': {'Anna': {'Fritz': {'Hans': 8},\r\n                                            'Maria': {'Kasimir': 7}}}}},\r\n 'Hans': {'Fritz': {'Anna': {'Joao': {'Wolfgang': {'G\u00c3\u00bcnther': 9}},\r\n                             'Maria': {'Kasimir': 10}}}},\r\n 'Joao': {'Anna': {'Fritz': {'Hans': 13},\r\n                   'Maria': {'Kasimir': 12}},\r\n          'Wolfgang': {'G\u00c3\u00bcnther': 11}},\r\n 'Kasimir': {'Maria': {'Anna': {'Fritz': {'Hans': 15},\r\n                                'Joao': {'Wolfgang': {'G\u00c3\u00bcnther': 14}}}}},\r\n 'Maria': {'Anna': {'Fritz': {'Hans': 17},\r\n                    'Joao': {'Wolfgang': {'G\u00c3\u00bcnther': 16}}},\r\n           'Kasimir': 18},\r\n 'Wolfgang': {'G\u00c3\u00bcnther': 19,\r\n              'Joao': {'Anna': {'Fritz': {'Hans': 21},\r\n                                'Maria': {'Kasimir': 20}}}}}\r\n3) --------------------------------------------------------------\r\n[(1,\r\n  ('G\u00c3\u00bcnther',\r\n   'Wolfgang')),\r\n (2,\r\n  ('Anna',\r\n   'Joao',\r\n   'Wolfgang'))]\r\n{'Anna': {'Joao': {'Wolfgang': 2}},\r\n 'G\u00c3\u00bcnther': {'Wolfgang': 1}}\r\n4) --------------------------------------------------------------\r\n[(1,\r\n  ('Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (2,\r\n  ('Wolfgang',\r\n   'Joao',\r\n   'Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (3,\r\n  ('Wolfgang',\r\n   'Joao',\r\n   'Anna',\r\n   'Fritz',\r\n   'Hans')),\r\n (4,\r\n  ('Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (5,\r\n  ('Anna',\r\n   'Fritz',\r\n   'Hans'))]\r\n{'Anna': {'Fritz': {'Hans': 5},\r\n          'Maria': {'Kasimir': 4}},\r\n 'Wolfgang': {'G\u00c3\u00bcnther': 1,\r\n              'Joao': {'Anna': {'Fritz': {'Hans': 3},\r\n                                'Maria': {'Kasimir': 2}}}}}\r\n5) --------------------------------------------------------------\r\n[(1,\r\n  ('Anna',\r\n   'Joao',\r\n   'Wolfgang',\r\n   'G\u00c3\u00bcnther')),\r\n (2,\r\n  ('Anna',\r\n   'Maria',\r\n   'Kasimir')),\r\n (3,\r\n  ('Anna',\r\n   'Fritz',\r\n   'Hans'))]\r\n{'Anna': {'Fritz': {'Hans': 3},\r\n          'Joao': {'Wolfgang': {'G\u00c3\u00bcnther': 1}},\r\n          'Maria': {'Kasimir': 2}}}\r\n6) --------------------------------------------------------------\r\n1\r\n{'Anna': {'Fritz': {'Hans': 3},\r\n          'Joao': {'Wolfgang': {'G\u00c3\u00bcnther': 'new_value_edit'}},\r\n          'Maria': {'Kasimir': 2}}}\r\nnew_value_edit\r\n7) --------------------------------------------------------------\r\n\r\n\r\n\r\n\r\ntreedict(\r\n    pairs_list: list | tuple, main_mapping_keys: tuple | list = (), bi_rl_lr: str = \"lr\"\r\n):\r\n    \"\"\"\r\n    This function takes a list or tuple of pairs, a tuple or list of main mapping keys, and a string indicating the type\r\n    of bidirectional mapping to be used. It returns a tuple of flattened dictionary and a nested dictionary.\r\n\r\n    :param pairs_list: A list or tuple of pairs.\r\n    :type pairs_list: list | tuple\r\n    :param main_mapping_keys: A tuple or list of main mapping keys.\r\n    :type main_mapping_keys: tuple | list\r\n    :param bi_rl_lr: A string indicating the type of bidirectional mapping to be used. Default is \"lr\", Valid options are\r\n                     lr - left to right / rl - right to left / bi - bidirectional\r\n    :type bi_rl_lr: str\r\n    :return: A tuple of flattened dictionary and a nested dictionary.\r\n    :rtype: tuple\r\n    \"\"\"\r\n\t\r\nedit_value_in_treedict(d: dict, keys: list | tuple, newvalue: Any) -> None:\r\n    \"\"\"\r\n    Edit the value of a nested dictionary given a list of keys.\r\n\r\n    Args:\r\n        d (dict): The nested dictionary to be edited.\r\n        keys (list,tuple): A list of keys representing the path to the value to be edited.\r\n        newvalue (Any): The new value to be assigned to the specified key path.\r\n\r\n    Returns:\r\n        None: This function does not return anything, but it changes the ORIGINAL dict! If you want to keep a copy of\r\n        the original dict, use copy.deepcopy(d) before you call the function\r\n\r\n    Raises:\r\n        KeyError: If any of the keys in the list do not exist in the dictionary.\r\n\r\n    Example:\r\n        d = {'a': {'b': {'c': 1}}}\r\n        keys = ['a', 'b', 'c']\r\n        newvalue = 2\r\n        edit_value_in_treedict(d, keys, newvalue)\r\n        # d is now {'a': {'b': {'c': 2}}}\r\n    \"\"\"\t\r\n\t\r\n\t\r\nget_value_in_treedict(d: dict, keys: list | tuple) -> Any:\r\n    \"\"\"\r\n    Returns the value in a nested dictionary `d` at the specified `keys`.\r\n\r\n    Args:\r\n        d (dict): The nested dictionary to search for the value.\r\n        keys (list|tuple): The list or tuple of keys to traverse the nested dictionary.\r\n\r\n    Returns:\r\n        Any: The value at the specified `keys` in the nested dictionary `d`.\r\n\r\n    Raises:\r\n        TypeError: If `d` is not a dictionary or `keys` is not a list or tuple.\r\n        KeyError: If any of the keys in `keys` do not exist in the nested dictionary `d`.\r\n    \"\"\"\r\n\t\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Converts a list of tuples to a nested \"family tree dict",
    "version": "0.10",
    "split_keywords": [
        "tree",
        "list",
        "recursive",
        "dict",
        "convert",
        "family tree"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eea2c845e5b62b171bab1fbcc8ffd64f9acd6ae0fe8e26c1ecf67dbee7965d88",
                "md5": "48e146e4730ea93a5a7eac980327cf42",
                "sha256": "d820de0381e7cc18be168d3fa3d2cd2d0ee8aef1185c7c1f1e468d93685f90e7"
            },
            "downloads": -1,
            "filename": "list2tree-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "48e146e4730ea93a5a7eac980327cf42",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9523,
            "upload_time": "2023-04-20T04:27:22",
            "upload_time_iso_8601": "2023-04-20T04:27:22.876970Z",
            "url": "https://files.pythonhosted.org/packages/ee/a2/c845e5b62b171bab1fbcc8ffd64f9acd6ae0fe8e26c1ecf67dbee7965d88/list2tree-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "58435bad03e51c36cd0a5140eff13c2c3595d3ad11bdff5ba7b4fe39b5e5c748",
                "md5": "3f4ebf6d782b6c49b693142075bc4c19",
                "sha256": "0eabfb47d77e96e24a8bfc444746db935aa550c08b85efd0996dc13606f11b6c"
            },
            "downloads": -1,
            "filename": "list2tree-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "3f4ebf6d782b6c49b693142075bc4c19",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6712,
            "upload_time": "2023-04-20T04:27:25",
            "upload_time_iso_8601": "2023-04-20T04:27:25.084247Z",
            "url": "https://files.pythonhosted.org/packages/58/43/5bad03e51c36cd0a5140eff13c2c3595d3ad11bdff5ba7b4fe39b5e5c748/list2tree-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-20 04:27:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hansalemaos",
    "github_project": "list2tree",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "list2tree"
}
        
Elapsed time: 0.07579s