educative.io

Educative

Compiler error probably coming from another issue. Program isnt running

def reverse(lst):
if lst.is_empty():
return lst

head = lst.get_head()

if head.next_element is None:
return lst

prev, curr = None, head
while curr:
temp = curr.next_element
curr.next_element = prev
prev = curr
curr = temp
return prev

gives

Traceback (most recent call last):
File “main.py”, line 122, in
main()
File “main.py”, line 102, in main
results = executeTests()
File “main.py”, line 88, in executeTests
actual_output = elements(newlist)
File “main.py”, line 7, in elements
start = lst.get_head()
AttributeError: ‘Node’ object has no attribute ‘get_head’

Seems like some other problem is showing an issue. Could you please check.


Course: Educative: Interactive Courses for Software Developers
Lesson: Educative: Interactive Courses for Software Developers

1 Like

Hi!

I got the same issue.

The reason was that we are returning the “prev” itself. We should reassign the head of the linked list


Course: Educative: Interactive Courses for Software Developers
Lesson: Educative: Interactive Courses for Software Developers