Converts lists to tuples, including nested lists. All other non-list inputs are passed through unmodified. This function is intended to be used to convert potentially nested lists from json files into valid nodes. Examples -------- >>> _to_tuple([1, 2, [3, 4]]) (1, 2, (
(x)
| 11 | |
| 12 | |
| 13 | def _to_tuple(x): |
| 14 | """Converts lists to tuples, including nested lists. |
| 15 | |
| 16 | All other non-list inputs are passed through unmodified. This function is |
| 17 | intended to be used to convert potentially nested lists from json files |
| 18 | into valid nodes. |
| 19 | |
| 20 | Examples |
| 21 | -------- |
| 22 | >>> _to_tuple([1, 2, [3, 4]]) |
| 23 | (1, 2, (3, 4)) |
| 24 | """ |
| 25 | if not isinstance(x, (tuple, list)): |
| 26 | return x |
| 27 | return tuple(map(_to_tuple, x)) |
| 28 | |
| 29 | |
| 30 | def node_link_graph(data, directed=False, multigraph=True, attrs=None): |