MacSG

LabComPro-Mid_3

Mar 29th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def in_list(lst, x):
  2.    
  3.     if len(lst) == 1:
  4.         return lst[0] == x
  5.  
  6.     else:
  7.         if lst[-1] == x:
  8.             return True
  9.         else :
  10.             return in_list(lst[:-1], x)
  11.  
  12. #Main Program
  13. lst = ['a','b','c']
  14. x = 'a'
  15. print(in_list(lst, x))
  16. print(in_list(['ant','bird','cat'],'dog'))
Advertisement
Add Comment
Please, Sign In to add comment