Source code for networkx.readwrite.json_graph.node_link

from itertools import count

import networkx as nx

__all__ = ["node_link_data", "node_link_graph"]


def _to_tuple(x):
    """将列表转换为元组,包括嵌套列表。

所有其他非列表输入保持不变。此函数旨在用于将可能嵌套的列表从JSON文件转换为有效的节点。

Examples
--------
>>> _to_tuple([1, 2, [3, 4]])
(1, 2, (3, 4))
"""
    if not isinstance(x, tuple | list):
        return x
    return tuple(map(_to_tuple, x))