Skip to content

Commit 2e216ab

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 134c7ab commit 2e216ab

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

graphs/array_to_graph.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,22 @@
2222
SOFTWARE.
2323
"""
2424

25-
# https://gist.github.com/harigro/28df9ec639f74f217473f85065acf9d8
25+
# https://gist.github.com/harigro/28df9ec639f74f217473f85065acf9d8
2626

2727
from typing import List, Dict
2828

29+
2930
def divide_array_to_graph(arr: List[int], base: int) -> Dict[int, List[int]]:
3031
"""
31-
Splits an array into smaller parts and returns them in a dictionary, simulating a graph
32+
Splits an array into smaller parts and returns them in a dictionary, simulating a graph
3233
structure where each part of the array is a node connected to other parts.
3334
3435
Args:
3536
arr (List[int]): The array to be divided.
3637
base (int): The divisor that determines the number of parts.
3738
3839
Returns:
39-
Dict[int, List[int]]: A dictionary representing the graph structure,
40+
Dict[int, List[int]]: A dictionary representing the graph structure,
4041
where each key is a node and the value is a list of connected nodes.
4142
4243
Example:
@@ -46,21 +47,23 @@ def divide_array_to_graph(arr: List[int], base: int) -> Dict[int, List[int]]:
4647
{0: [1, 2, 3, 4], 1: [5, 6, 7, 8]}
4748
"""
4849
length = len(arr)
49-
parts = len(arr)//base # Desired number of parts
50+
parts = len(arr) // base # Desired number of parts
5051
part_size = length // parts # Size of each part
51-
52+
5253
# Divide the array into smaller parts
53-
result = [arr[i * part_size: (i + 1) * part_size] for i in range(parts)]
54-
54+
result = [arr[i * part_size : (i + 1) * part_size] for i in range(parts)]
55+
5556
# Insert the result into a dictionary with keys from 0 to 3
5657
result_dict = {i: result[i] for i in range(parts)}
57-
58+
5859
return result_dict
5960

61+
6062
if __name__ == "__main__":
6163
# Example usage
6264
array = [1, 2, 3, 4, 5, 6, 7, 8]
6365
print(divide_array_to_graph(array, 2))
64-
66+
6567
import doctest
66-
doctest.testmod()
68+
69+
doctest.testmod()

0 commit comments

Comments
 (0)