Back
def len_link(lst):"""Returns the length of the link. >>> lst = link(1, link(2, link(3, link(4)))) >>> len_link(lst) 4 >>> len_link(empty) 0 """
def len_link(lst):
"""Returns the length of the link.
>>> lst = link(1, link(2, link(3, link(4))))
>>> len_link(lst)
4
>>> len_link(empty)
0
"""
Hi, can anyone tell me how to find the length of a linked list?
You can also use this:
def len_link(list): temp = list.head count =0 while (temp): count +=1 temp = temp.nextreturn count
def len_link(list):
temp = list.head
count =0
while (temp):
count +=1
temp = temp.next
return count
I recommend enrolling in this Python Course by Intelllipaat to learn Python.
Also, you can watch this video on the linked list in Python:
31k questions
32.8k answers
501 comments
693 users