@@ -25,18 +25,32 @@ def make_linked_list(elements_list: list | tuple) -> Node:
25
25
Creates a Linked List from the elements of the given sequence
26
26
(list/tuple) and returns the head of the Linked List.
27
27
28
- >>> make_linked_list([1, 3, 5, 32, 44, 12, 43])
29
- <1> ---> <3> ---> <5> ---> <32> ---> <44> ---> <12> ---> <43> ---> <END>
28
+ >>> make_linked_list([])
29
+ Traceback (most recent call last):
30
+ ...
31
+ ValueError: The Elements List is empty
32
+ >>> make_linked_list(())
33
+ Traceback (most recent call last):
34
+ ...
35
+ ValueError: The Elements List is empty
30
36
>>> make_linked_list([1])
31
37
<1> ---> <END>
32
38
>>> make_linked_list((1,))
33
39
<1> ---> <END>
40
+ >>> make_linked_list([1, 3, 5, 32, 44, 12, 43])
41
+ <1> ---> <3> ---> <5> ---> <32> ---> <44> ---> <12> ---> <43> ---> <END>
42
+ >>> make_linked_list((1, 3, 5, 32, 44, 12, 43))
43
+ <1> ---> <3> ---> <5> ---> <32> ---> <44> ---> <12> ---> <43> ---> <END>
34
44
"""
35
45
46
+ # if elements_list is empty
36
47
if not elements_list :
37
- raise Exception ("The Elements List is empty" )
48
+ raise ValueError ("The Elements List is empty" )
49
+
50
+ # Set first element as Head
38
51
head = Node (elements_list [0 ])
39
52
current = head
53
+ # Loop through elements from position 1
40
54
for data in elements_list [1 :]:
41
55
current .next = Node (data )
42
56
current = current .next
0 commit comments