We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
 Improve test coverage for algorithms in load centrality
<!-- If you have a general question about NetworkX, please use the discussions tab to create a new discussion -->

<!--- Provide a general summary of the issue in the Title above -->

Currently we don't have full coverage for the algorithms in load centrality. Code blocks which are highlighted with red at codcov https://app.codecov.io/gh/networkx/networkx/blob/main/networkx/algorithms/centrality/load.py don't have corresponding tests. The tests should be added in https://github.com/networkx/networkx/blob/main/networkx/algorithms/centrality/tests/test_load_centrality.py

### Current Behavior

<!--- Tell us what happens instead of the expected behavior -->

We don't test all the paths the code can take us.

### Expected Behavior

<!--- Tell us what should happen -->

We should be testing everything so there aren't any surprises.

### Steps to Reproduce

<!--- Provide a minimal example that reproduces the bug -->

Visit https://app.codecov.io/gh/networkx/networkx/blob/main/networkx/algorithms/centrality/load.py


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `networkx/readwrite/adjlist.py`
Content:
```
1 """
2 **************
3 Adjacency List
4 **************
5 Read and write NetworkX graphs as adjacency lists.
6 
7 Adjacency list format is useful for graphs without data associated
8 with nodes or edges and for nodes that can be meaningfully represented
9 as strings.
10 
11 Format
12 ------
13 The adjacency list format consists of lines with node labels.  The
14 first label in a line is the source node.  Further labels in the line
15 are considered target nodes and are added to the graph along with an edge
16 between the source node and target node.
17 
18 The graph with edges a-b, a-c, d-e can be represented as the following
19 adjacency list (anything following the # in a line is a comment)::
20 
21      a b c # source target target
22      d e
23 """
24 
25 __all__ = ["generate_adjlist", "write_adjlist", "parse_adjlist", "read_adjlist"]
26 
27 import networkx as nx
28 from networkx.utils import open_file
29 
30 
31 def generate_adjlist(G, delimiter=" "):
32     """Generate a single line of the graph G in adjacency list format.
33 
34     Parameters
35     ----------
36     G : NetworkX graph
37 
38     delimiter : string, optional
39        Separator for node labels
40 
41     Returns
42     -------
43     lines : string
44         Lines of data in adjlist format.
45 
46     Examples
47     --------
48     >>> G = nx.lollipop_graph(4, 3)
49     >>> for line in nx.generate_adjlist(G):
50     ...     print(line)
51     0 1 2 3
52     1 2 3
53     2 3
54     3 4
55     4 5
56     5 6
57     6
58 
59     See Also
60     --------
61     write_adjlist, read_adjlist
62 
63     """
64     directed = G.is_directed()
65     seen = set()
66     for s, nbrs in G.adjacency():
67         line = str(s) + delimiter
68         for t, data in nbrs.items():
69             if not directed and t in seen:
70                 continue
71             if G.is_multigraph():
72                 for d in data.values():
73                     line += str(t) + delimiter
74             else:
75                 line += str(t) + delimiter
76         if not directed:
77             seen.add(s)
78         yield line[: -len(delimiter)]
79 
80 
81 @open_file(1, mode="wb")
82 def write_adjlist(G, path, comments="#", delimiter=" ", encoding="utf-8"):
83     """Write graph G in single-line adjacency-list format to path.
84 
85 
86     Parameters
87     ----------
88     G : NetworkX graph
89 
90     path : string or file
91        Filename or file handle for data output.
92        Filenames ending in .gz or .bz2 will be compressed.
93 
94     comments : string, optional
95        Marker for comment lines
96 
97     delimiter : string, optional
98        Separator for node labels
99 
100     encoding : string, optional
101        Text encoding.
102 
103     Examples
104     --------
105     >>> G = nx.path_graph(4)
106     >>> nx.write_adjlist(G, "test.adjlist")
107 
108     The path can be a filehandle or a string with the name of the file. If a
109     filehandle is provided, it has to be opened in 'wb' mode.
110 
111     >>> fh = open("test.adjlist", "wb")
112     >>> nx.write_adjlist(G, fh)
113 
114     Notes
115     -----
116     This format does not store graph, node, or edge data.
117 
118     See Also
119     --------
120     read_adjlist, generate_adjlist
121     """
122     import sys
123     import time
124 
125     pargs = comments + " ".join(sys.argv) + "\n"
126     header = (
127         pargs
128         + comments
129         + f" GMT {time.asctime(time.gmtime())}\n"
130         + comments
131         + f" {G.name}\n"
132     )
133     path.write(header.encode(encoding))
134 
135     for line in generate_adjlist(G, delimiter):
136         line += "\n"
137         path.write(line.encode(encoding))
138 
139 
140 def parse_adjlist(
141     lines, comments="#", delimiter=None, create_using=None, nodetype=None
142 ):
143     """Parse lines of a graph adjacency list representation.
144 
145     Parameters
146     ----------
147     lines : list or iterator of strings
148         Input data in adjlist format
149 
150     create_using : NetworkX graph constructor, optional (default=nx.Graph)
151        Graph type to create. If graph instance, then cleared before populated.
152 
153     nodetype : Python type, optional
154        Convert nodes to this type.
155 
156     comments : string, optional
157        Marker for comment lines
158 
159     delimiter : string, optional
160        Separator for node labels.  The default is whitespace.
161 
162     Returns
163     -------
164     G: NetworkX graph
165         The graph corresponding to the lines in adjacency list format.
166 
167     Examples
168     --------
169     >>> lines = ["1 2 5", "2 3 4", "3 5", "4", "5"]
170     >>> G = nx.parse_adjlist(lines, nodetype=int)
171     >>> nodes = [1, 2, 3, 4, 5]
172     >>> all(node in G for node in nodes)
173     True
174     >>> edges = [(1, 2), (1, 5), (2, 3), (2, 4), (3, 5)]
175     >>> all((u, v) in G.edges() or (v, u) in G.edges() for (u, v) in edges)
176     True
177 
178     See Also
179     --------
180     read_adjlist
181 
182     """
183     G = nx.empty_graph(0, create_using)
184     for line in lines:
185         p = line.find(comments)
186         if p >= 0:
187             line = line[:p]
188         if not len(line):
189             continue
190         vlist = line.strip().split(delimiter)
191         u = vlist.pop(0)
192         # convert types
193         if nodetype is not None:
194             try:
195                 u = nodetype(u)
196             except BaseException as err:
197                 raise TypeError(
198                     f"Failed to convert node ({u}) to type " f"{nodetype}"
199                 ) from err
200         G.add_node(u)
201         if nodetype is not None:
202             try:
203                 vlist = list(map(nodetype, vlist))
204             except BaseException as err:
205                 raise TypeError(
206                     f"Failed to convert nodes ({','.join(vlist)}) to type {nodetype}"
207                 ) from err
208         G.add_edges_from([(u, v) for v in vlist])
209     return G
210 
211 
212 @open_file(0, mode="rb")
213 def read_adjlist(
214     path,
215     comments="#",
216     delimiter=None,
217     create_using=None,
218     nodetype=None,
219     encoding="utf-8",
220 ):
221     """Read graph in adjacency list format from path.
222 
223     Parameters
224     ----------
225     path : string or file
226        Filename or file handle to read.
227        Filenames ending in .gz or .bz2 will be uncompressed.
228 
229     create_using : NetworkX graph constructor, optional (default=nx.Graph)
230        Graph type to create. If graph instance, then cleared before populated.
231 
232     nodetype : Python type, optional
233        Convert nodes to this type.
234 
235     comments : string, optional
236        Marker for comment lines
237 
238     delimiter : string, optional
239        Separator for node labels.  The default is whitespace.
240 
241     Returns
242     -------
243     G: NetworkX graph
244         The graph corresponding to the lines in adjacency list format.
245 
246     Examples
247     --------
248     >>> G = nx.path_graph(4)
249     >>> nx.write_adjlist(G, "test.adjlist")
250     >>> G = nx.read_adjlist("test.adjlist")
251 
252     The path can be a filehandle or a string with the name of the file. If a
253     filehandle is provided, it has to be opened in 'rb' mode.
254 
255     >>> fh = open("test.adjlist", "rb")
256     >>> G = nx.read_adjlist(fh)
257 
258     Filenames ending in .gz or .bz2 will be compressed.
259 
260     >>> nx.write_adjlist(G, "test.adjlist.gz")
261     >>> G = nx.read_adjlist("test.adjlist.gz")
262 
263     The optional nodetype is a function to convert node strings to nodetype.
264 
265     For example
266 
267     >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
268 
269     will attempt to convert all nodes to integer type.
270 
271     Since nodes must be hashable, the function nodetype must return hashable
272     types (e.g. int, float, str, frozenset - or tuples of those, etc.)
273 
274     The optional create_using parameter indicates the type of NetworkX graph
275     created.  The default is `nx.Graph`, an undirected graph.
276     To read the data as a directed graph use
277 
278     >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
279 
280     Notes
281     -----
282     This format does not store graph or node data.
283 
284     See Also
285     --------
286     write_adjlist
287     """
288     lines = (line.decode(encoding) for line in path)
289     return parse_adjlist(
290         lines,
291         comments=comments,
292         delimiter=delimiter,
293         create_using=create_using,
294         nodetype=nodetype,
295     )
296
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/networkx/readwrite/adjlist.py b/networkx/readwrite/adjlist.py
--- a/networkx/readwrite/adjlist.py
+++ b/networkx/readwrite/adjlist.py
@@ -60,6 +60,14 @@
     --------
     write_adjlist, read_adjlist
 
+    Notes
+    -----
+    The default `delimiter=" "` will result in unexpected results if node names contain
+    whitespace characters. To avoid this problem, specify an alternate delimiter when spaces are
+    valid in node names.
+
+    NB: This option is not available for data that isn't user-generated.
+
     """
     directed = G.is_directed()
     seen = set()
@@ -113,6 +121,11 @@
 
     Notes
     -----
+    The default `delimiter=" "` will result in unexpected results if node names contain
+    whitespace characters. To avoid this problem, specify an alternate delimiter when spaces are
+    valid in node names.
+    NB: This option is not available for data that isn't user-generated.
+
     This format does not store graph, node, or edge data.
 
     See Also

{"golden_diff": "diff --git a/networkx/readwrite/adjlist.py b/networkx/readwrite/adjlist.py\n--- a/networkx/readwrite/adjlist.py\n+++ b/networkx/readwrite/adjlist.py\n@@ -60,6 +60,14 @@\n     --------\n     write_adjlist, read_adjlist\n \n+    Notes\n+    -----\n+    The default `delimiter=\" \"` will result in unexpected results if node names contain\n+    whitespace characters. To avoid this problem, specify an alternate delimiter when spaces are\n+    valid in node names.\n+\n+    NB: This option is not available for data that isn't user-generated.\n+\n     \"\"\"\n     directed = G.is_directed()\n     seen = set()\n@@ -113,6 +121,11 @@\n \n     Notes\n     -----\n+    The default `delimiter=\" \"` will result in unexpected results if node names contain\n+    whitespace characters. To avoid this problem, specify an alternate delimiter when spaces are\n+    valid in node names.\n+    NB: This option is not available for data that isn't user-generated.\n+\n     This format does not store graph, node, or edge data.\n \n     See Also\n", "issue": " Improve test coverage for algorithms in load centrality\n<!-- If you have a general question about NetworkX, please use the discussions tab to create a new discussion -->\r\n\r\n<!--- Provide a general summary of the issue in the Title above -->\r\n\r\nCurrently we don't have full coverage for the algorithms in load centrality. Code blocks which are highlighted with red at codcov https://app.codecov.io/gh/networkx/networkx/blob/main/networkx/algorithms/centrality/load.py don't have corresponding tests. The tests should be added in https://github.com/networkx/networkx/blob/main/networkx/algorithms/centrality/tests/test_load_centrality.py\r\n\r\n### Current Behavior\r\n\r\n<!--- Tell us what happens instead of the expected behavior -->\r\n\r\nWe don't test all the paths the code can take us.\r\n\r\n### Expected Behavior\r\n\r\n<!--- Tell us what should happen -->\r\n\r\nWe should be testing everything so there aren't any surprises.\r\n\r\n### Steps to Reproduce\r\n\r\n<!--- Provide a minimal example that reproduces the bug -->\r\n\r\nVisit https://app.codecov.io/gh/networkx/networkx/blob/main/networkx/algorithms/centrality/load.py\r\n\n", "before_files": [{"content": "\"\"\"\n**************\nAdjacency List\n**************\nRead and write NetworkX graphs as adjacency lists.\n\nAdjacency list format is useful for graphs without data associated\nwith nodes or edges and for nodes that can be meaningfully represented\nas strings.\n\nFormat\n------\nThe adjacency list format consists of lines with node labels.  The\nfirst label in a line is the source node.  Further labels in the line\nare considered target nodes and are added to the graph along with an edge\nbetween the source node and target node.\n\nThe graph with edges a-b, a-c, d-e can be represented as the following\nadjacency list (anything following the # in a line is a comment)::\n\n     a b c # source target target\n     d e\n\"\"\"\n\n__all__ = [\"generate_adjlist\", \"write_adjlist\", \"parse_adjlist\", \"read_adjlist\"]\n\nimport networkx as nx\nfrom networkx.utils import open_file\n\n\ndef generate_adjlist(G, delimiter=\" \"):\n    \"\"\"Generate a single line of the graph G in adjacency list format.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n\n    delimiter : string, optional\n       Separator for node labels\n\n    Returns\n    -------\n    lines : string\n        Lines of data in adjlist format.\n\n    Examples\n    --------\n    >>> G = nx.lollipop_graph(4, 3)\n    >>> for line in nx.generate_adjlist(G):\n    ...     print(line)\n    0 1 2 3\n    1 2 3\n    2 3\n    3 4\n    4 5\n    5 6\n    6\n\n    See Also\n    --------\n    write_adjlist, read_adjlist\n\n    \"\"\"\n    directed = G.is_directed()\n    seen = set()\n    for s, nbrs in G.adjacency():\n        line = str(s) + delimiter\n        for t, data in nbrs.items():\n            if not directed and t in seen:\n                continue\n            if G.is_multigraph():\n                for d in data.values():\n                    line += str(t) + delimiter\n            else:\n                line += str(t) + delimiter\n        if not directed:\n            seen.add(s)\n        yield line[: -len(delimiter)]\n\n\n@open_file(1, mode=\"wb\")\ndef write_adjlist(G, path, comments=\"#\", delimiter=\" \", encoding=\"utf-8\"):\n    \"\"\"Write graph G in single-line adjacency-list format to path.\n\n\n    Parameters\n    ----------\n    G : NetworkX graph\n\n    path : string or file\n       Filename or file handle for data output.\n       Filenames ending in .gz or .bz2 will be compressed.\n\n    comments : string, optional\n       Marker for comment lines\n\n    delimiter : string, optional\n       Separator for node labels\n\n    encoding : string, optional\n       Text encoding.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(4)\n    >>> nx.write_adjlist(G, \"test.adjlist\")\n\n    The path can be a filehandle or a string with the name of the file. If a\n    filehandle is provided, it has to be opened in 'wb' mode.\n\n    >>> fh = open(\"test.adjlist\", \"wb\")\n    >>> nx.write_adjlist(G, fh)\n\n    Notes\n    -----\n    This format does not store graph, node, or edge data.\n\n    See Also\n    --------\n    read_adjlist, generate_adjlist\n    \"\"\"\n    import sys\n    import time\n\n    pargs = comments + \" \".join(sys.argv) + \"\\n\"\n    header = (\n        pargs\n        + comments\n        + f\" GMT {time.asctime(time.gmtime())}\\n\"\n        + comments\n        + f\" {G.name}\\n\"\n    )\n    path.write(header.encode(encoding))\n\n    for line in generate_adjlist(G, delimiter):\n        line += \"\\n\"\n        path.write(line.encode(encoding))\n\n\ndef parse_adjlist(\n    lines, comments=\"#\", delimiter=None, create_using=None, nodetype=None\n):\n    \"\"\"Parse lines of a graph adjacency list representation.\n\n    Parameters\n    ----------\n    lines : list or iterator of strings\n        Input data in adjlist format\n\n    create_using : NetworkX graph constructor, optional (default=nx.Graph)\n       Graph type to create. If graph instance, then cleared before populated.\n\n    nodetype : Python type, optional\n       Convert nodes to this type.\n\n    comments : string, optional\n       Marker for comment lines\n\n    delimiter : string, optional\n       Separator for node labels.  The default is whitespace.\n\n    Returns\n    -------\n    G: NetworkX graph\n        The graph corresponding to the lines in adjacency list format.\n\n    Examples\n    --------\n    >>> lines = [\"1 2 5\", \"2 3 4\", \"3 5\", \"4\", \"5\"]\n    >>> G = nx.parse_adjlist(lines, nodetype=int)\n    >>> nodes = [1, 2, 3, 4, 5]\n    >>> all(node in G for node in nodes)\n    True\n    >>> edges = [(1, 2), (1, 5), (2, 3), (2, 4), (3, 5)]\n    >>> all((u, v) in G.edges() or (v, u) in G.edges() for (u, v) in edges)\n    True\n\n    See Also\n    --------\n    read_adjlist\n\n    \"\"\"\n    G = nx.empty_graph(0, create_using)\n    for line in lines:\n        p = line.find(comments)\n        if p >= 0:\n            line = line[:p]\n        if not len(line):\n            continue\n        vlist = line.strip().split(delimiter)\n        u = vlist.pop(0)\n        # convert types\n        if nodetype is not None:\n            try:\n                u = nodetype(u)\n            except BaseException as err:\n                raise TypeError(\n                    f\"Failed to convert node ({u}) to type \" f\"{nodetype}\"\n                ) from err\n        G.add_node(u)\n        if nodetype is not None:\n            try:\n                vlist = list(map(nodetype, vlist))\n            except BaseException as err:\n                raise TypeError(\n                    f\"Failed to convert nodes ({','.join(vlist)}) to type {nodetype}\"\n                ) from err\n        G.add_edges_from([(u, v) for v in vlist])\n    return G\n\n\n@open_file(0, mode=\"rb\")\ndef read_adjlist(\n    path,\n    comments=\"#\",\n    delimiter=None,\n    create_using=None,\n    nodetype=None,\n    encoding=\"utf-8\",\n):\n    \"\"\"Read graph in adjacency list format from path.\n\n    Parameters\n    ----------\n    path : string or file\n       Filename or file handle to read.\n       Filenames ending in .gz or .bz2 will be uncompressed.\n\n    create_using : NetworkX graph constructor, optional (default=nx.Graph)\n       Graph type to create. If graph instance, then cleared before populated.\n\n    nodetype : Python type, optional\n       Convert nodes to this type.\n\n    comments : string, optional\n       Marker for comment lines\n\n    delimiter : string, optional\n       Separator for node labels.  The default is whitespace.\n\n    Returns\n    -------\n    G: NetworkX graph\n        The graph corresponding to the lines in adjacency list format.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(4)\n    >>> nx.write_adjlist(G, \"test.adjlist\")\n    >>> G = nx.read_adjlist(\"test.adjlist\")\n\n    The path can be a filehandle or a string with the name of the file. If a\n    filehandle is provided, it has to be opened in 'rb' mode.\n\n    >>> fh = open(\"test.adjlist\", \"rb\")\n    >>> G = nx.read_adjlist(fh)\n\n    Filenames ending in .gz or .bz2 will be compressed.\n\n    >>> nx.write_adjlist(G, \"test.adjlist.gz\")\n    >>> G = nx.read_adjlist(\"test.adjlist.gz\")\n\n    The optional nodetype is a function to convert node strings to nodetype.\n\n    For example\n\n    >>> G = nx.read_adjlist(\"test.adjlist\", nodetype=int)\n\n    will attempt to convert all nodes to integer type.\n\n    Since nodes must be hashable, the function nodetype must return hashable\n    types (e.g. int, float, str, frozenset - or tuples of those, etc.)\n\n    The optional create_using parameter indicates the type of NetworkX graph\n    created.  The default is `nx.Graph`, an undirected graph.\n    To read the data as a directed graph use\n\n    >>> G = nx.read_adjlist(\"test.adjlist\", create_using=nx.DiGraph)\n\n    Notes\n    -----\n    This format does not store graph or node data.\n\n    See Also\n    --------\n    write_adjlist\n    \"\"\"\n    lines = (line.decode(encoding) for line in path)\n    return parse_adjlist(\n        lines,\n        comments=comments,\n        delimiter=delimiter,\n        create_using=create_using,\n        nodetype=nodetype,\n    )\n", "path": "networkx/readwrite/adjlist.py"}], "after_files": [{"content": "\"\"\"\n**************\nAdjacency List\n**************\nRead and write NetworkX graphs as adjacency lists.\n\nAdjacency list format is useful for graphs without data associated\nwith nodes or edges and for nodes that can be meaningfully represented\nas strings.\n\nFormat\n------\nThe adjacency list format consists of lines with node labels.  The\nfirst label in a line is the source node.  Further labels in the line\nare considered target nodes and are added to the graph along with an edge\nbetween the source node and target node.\n\nThe graph with edges a-b, a-c, d-e can be represented as the following\nadjacency list (anything following the # in a line is a comment)::\n\n     a b c # source target target\n     d e\n\"\"\"\n\n__all__ = [\"generate_adjlist\", \"write_adjlist\", \"parse_adjlist\", \"read_adjlist\"]\n\nimport networkx as nx\nfrom networkx.utils import open_file\n\n\ndef generate_adjlist(G, delimiter=\" \"):\n    \"\"\"Generate a single line of the graph G in adjacency list format.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n\n    delimiter : string, optional\n       Separator for node labels\n\n    Returns\n    -------\n    lines : string\n        Lines of data in adjlist format.\n\n    Examples\n    --------\n    >>> G = nx.lollipop_graph(4, 3)\n    >>> for line in nx.generate_adjlist(G):\n    ...     print(line)\n    0 1 2 3\n    1 2 3\n    2 3\n    3 4\n    4 5\n    5 6\n    6\n\n    See Also\n    --------\n    write_adjlist, read_adjlist\n\n    Notes\n    -----\n    The default `delimiter=\" \"` will result in unexpected results if node names contain\n    whitespace characters. To avoid this problem, specify an alternate delimiter when spaces are\n    valid in node names.\n\n    NB: This option is not available for data that isn't user-generated.\n\n    \"\"\"\n    directed = G.is_directed()\n    seen = set()\n    for s, nbrs in G.adjacency():\n        line = str(s) + delimiter\n        for t, data in nbrs.items():\n            if not directed and t in seen:\n                continue\n            if G.is_multigraph():\n                for d in data.values():\n                    line += str(t) + delimiter\n            else:\n                line += str(t) + delimiter\n        if not directed:\n            seen.add(s)\n        yield line[: -len(delimiter)]\n\n\n@open_file(1, mode=\"wb\")\ndef write_adjlist(G, path, comments=\"#\", delimiter=\" \", encoding=\"utf-8\"):\n    \"\"\"Write graph G in single-line adjacency-list format to path.\n\n\n    Parameters\n    ----------\n    G : NetworkX graph\n\n    path : string or file\n       Filename or file handle for data output.\n       Filenames ending in .gz or .bz2 will be compressed.\n\n    comments : string, optional\n       Marker for comment lines\n\n    delimiter : string, optional\n       Separator for node labels\n\n    encoding : string, optional\n       Text encoding.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(4)\n    >>> nx.write_adjlist(G, \"test.adjlist\")\n\n    The path can be a filehandle or a string with the name of the file. If a\n    filehandle is provided, it has to be opened in 'wb' mode.\n\n    >>> fh = open(\"test.adjlist\", \"wb\")\n    >>> nx.write_adjlist(G, fh)\n\n    Notes\n    -----\n    The default `delimiter=\" \"` will result in unexpected results if node names contain\n    whitespace characters. To avoid this problem, specify an alternate delimiter when spaces are\n    valid in node names.\n    NB: This option is not available for data that isn't user-generated.\n\n    This format does not store graph, node, or edge data.\n\n    See Also\n    --------\n    read_adjlist, generate_adjlist\n    \"\"\"\n    import sys\n    import time\n\n    pargs = comments + \" \".join(sys.argv) + \"\\n\"\n    header = (\n        pargs\n        + comments\n        + f\" GMT {time.asctime(time.gmtime())}\\n\"\n        + comments\n        + f\" {G.name}\\n\"\n    )\n    path.write(header.encode(encoding))\n\n    for line in generate_adjlist(G, delimiter):\n        line += \"\\n\"\n        path.write(line.encode(encoding))\n\n\ndef parse_adjlist(\n    lines, comments=\"#\", delimiter=None, create_using=None, nodetype=None\n):\n    \"\"\"Parse lines of a graph adjacency list representation.\n\n    Parameters\n    ----------\n    lines : list or iterator of strings\n        Input data in adjlist format\n\n    create_using : NetworkX graph constructor, optional (default=nx.Graph)\n       Graph type to create. If graph instance, then cleared before populated.\n\n    nodetype : Python type, optional\n       Convert nodes to this type.\n\n    comments : string, optional\n       Marker for comment lines\n\n    delimiter : string, optional\n       Separator for node labels.  The default is whitespace.\n\n    Returns\n    -------\n    G: NetworkX graph\n        The graph corresponding to the lines in adjacency list format.\n\n    Examples\n    --------\n    >>> lines = [\"1 2 5\", \"2 3 4\", \"3 5\", \"4\", \"5\"]\n    >>> G = nx.parse_adjlist(lines, nodetype=int)\n    >>> nodes = [1, 2, 3, 4, 5]\n    >>> all(node in G for node in nodes)\n    True\n    >>> edges = [(1, 2), (1, 5), (2, 3), (2, 4), (3, 5)]\n    >>> all((u, v) in G.edges() or (v, u) in G.edges() for (u, v) in edges)\n    True\n\n    See Also\n    --------\n    read_adjlist\n\n    \"\"\"\n    G = nx.empty_graph(0, create_using)\n    for line in lines:\n        p = line.find(comments)\n        if p >= 0:\n            line = line[:p]\n        if not len(line):\n            continue\n        vlist = line.strip().split(delimiter)\n        u = vlist.pop(0)\n        # convert types\n        if nodetype is not None:\n            try:\n                u = nodetype(u)\n            except BaseException as err:\n                raise TypeError(\n                    f\"Failed to convert node ({u}) to type \" f\"{nodetype}\"\n                ) from err\n        G.add_node(u)\n        if nodetype is not None:\n            try:\n                vlist = list(map(nodetype, vlist))\n            except BaseException as err:\n                raise TypeError(\n                    f\"Failed to convert nodes ({','.join(vlist)}) to type {nodetype}\"\n                ) from err\n        G.add_edges_from([(u, v) for v in vlist])\n    return G\n\n\n@open_file(0, mode=\"rb\")\ndef read_adjlist(\n    path,\n    comments=\"#\",\n    delimiter=None,\n    create_using=None,\n    nodetype=None,\n    encoding=\"utf-8\",\n):\n    \"\"\"Read graph in adjacency list format from path.\n\n    Parameters\n    ----------\n    path : string or file\n       Filename or file handle to read.\n       Filenames ending in .gz or .bz2 will be uncompressed.\n\n    create_using : NetworkX graph constructor, optional (default=nx.Graph)\n       Graph type to create. If graph instance, then cleared before populated.\n\n    nodetype : Python type, optional\n       Convert nodes to this type.\n\n    comments : string, optional\n       Marker for comment lines\n\n    delimiter : string, optional\n       Separator for node labels.  The default is whitespace.\n\n    Returns\n    -------\n    G: NetworkX graph\n        The graph corresponding to the lines in adjacency list format.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(4)\n    >>> nx.write_adjlist(G, \"test.adjlist\")\n    >>> G = nx.read_adjlist(\"test.adjlist\")\n\n    The path can be a filehandle or a string with the name of the file. If a\n    filehandle is provided, it has to be opened in 'rb' mode.\n\n    >>> fh = open(\"test.adjlist\", \"rb\")\n    >>> G = nx.read_adjlist(fh)\n\n    Filenames ending in .gz or .bz2 will be compressed.\n\n    >>> nx.write_adjlist(G, \"test.adjlist.gz\")\n    >>> G = nx.read_adjlist(\"test.adjlist.gz\")\n\n    The optional nodetype is a function to convert node strings to nodetype.\n\n    For example\n\n    >>> G = nx.read_adjlist(\"test.adjlist\", nodetype=int)\n\n    will attempt to convert all nodes to integer type.\n\n    Since nodes must be hashable, the function nodetype must return hashable\n    types (e.g. int, float, str, frozenset - or tuples of those, etc.)\n\n    The optional create_using parameter indicates the type of NetworkX graph\n    created.  The default is `nx.Graph`, an undirected graph.\n    To read the data as a directed graph use\n\n    >>> G = nx.read_adjlist(\"test.adjlist\", create_using=nx.DiGraph)\n\n    Notes\n    -----\n    This format does not store graph or node data.\n\n    See Also\n    --------\n    write_adjlist\n    \"\"\"\n    lines = (line.decode(encoding) for line in path)\n    return parse_adjlist(\n        lines,\n        comments=comments,\n        delimiter=delimiter,\n        create_using=create_using,\n        nodetype=nodetype,\n    )\n", "path": "networkx/readwrite/adjlist.py"}]}