Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 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 not cell.is_empty:
  11.                 return None
  12.             if cell.value == x:
  13.                 return n
  14.             return indx(cell.tail, n + 1)
  15.  
  16.         return indx(self, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement