Exercise 6
Write a Python program that returns the length of a given list without using the len() method.
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def lenList(L): # initialization of list length l = 0 # iterate over list items for x in L: # length increment l = l + 1 return l # Example L = ["python", "Java" , "C++" , "Django" , "Laravel"] print("the length of the list is: ", lenList(L)) # The output is: the length of the list is: 5 |
Younes Derfoufi
CRMEF OUJDA
1 thought on “Solution Exercise 6: python algorithm that determines the length of given list”