Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (55.6k points)

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?

1 Answer

0 votes
by (119k points)

You can also use this:

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:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 30, 2020 in Python by Sudhir_1997 (55.6k points)

Browse Categories

...