MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / edglist

Function edglist

graphs/basic_graphs.py:313–337  ·  view source on GitHub ↗

r""" Get the edges and number of edges from the user Parameters: None Returns: tuple: A tuple containing a list of edges and number of edges Example: >>> # Simulate user input for 3 edges and 4 vertices: (1, 2), (2, 3), (3, 4) >>> input_data = "4 3\n1 2\n2

()

Source from the content-addressed store, hash-verified

311
312
313def edglist():
314 r"""
315 Get the edges and number of edges from the user
316
317 Parameters:
318 None
319
320 Returns:
321 tuple: A tuple containing a list of edges and number of edges
322
323 Example:
324 >>> # Simulate user input for 3 edges and 4 vertices: (1, 2), (2, 3), (3, 4)
325 >>> input_data = "4 3\n1 2\n2 3\n3 4\n"
326 >>> import sys,io
327 >>> original_input = sys.stdin
328 >>> sys.stdin = io.StringIO(input_data) # Redirect stdin for testing
329 >>> edglist()
330 ([(1, 2), (2, 3), (3, 4)], 4)
331 >>> sys.stdin = original_input # Restore original stdin
332 """
333 n, m = tuple(map(int, input().split(" ")))
334 edges = []
335 for _ in range(m):
336 edges.append(tuple(map(int, input().split(" "))))
337 return edges, n
338
339
340"""

Callers

nothing calls this directly

Calls 2

splitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected