Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1.     def index(self, x):
  2.         '''
  3.        Returns the first index i in the linked list, where the value x is found. Returns None if none of the Cells
  4.        has a value of x.
  5.  
  6.        The first element in the linked list has the index 0.
  7.        '''
  8.  
  9.         def indx(cell, n):
  10.             if cell.value == x:
  11.                 return n
  12.             elif cell.is_empty:
  13.                 return None
  14.             else:
  15.                 return indx(cell.tail, n + 1)
  16.  
  17.         return indx(self, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement