Advertisement
Guest User

Untitled

a guest
Jan 10th, 2014
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. def all_ints(lst):
  2.     ''' (list) -> bool
  3.  
  4.    Return True iff all elements in lst are ints.
  5.  
  6.    >>> all_ints([1, 2])
  7.    True
  8.    '''
  9.     ok = True
  10.     for s in lst:
  11.         if not isinstance(s, int):
  12.             ok = False
  13.     return ok
  14.  
  15.  
  16. def is_tuple_of_str_list(t, func_name):
  17.     ''' (object, str) -> NoneType
  18.  
  19.    Check whether t is a 2-element tuple where the first element is a string
  20.    and the second element is a 4-element list of ints.
  21.    '''
  22.     assert (isinstance(t, tuple) and len(t) == 2 and isinstance(t[0], str) \
  23.            and isinstance(t[1], list) and len(t[1]) == 4 \
  24.            and all_ints(t[1])
  25.            ), \
  26.            '{0} should return tuple of (str, list of four ints), but returned \
  27.           {1}.'.format(func_name, t)
  28.  
  29.  
  30. def is_tuple_of_str_None(t, func_name):
  31.     '''(object, str) -> NoneType
  32.  
  33.    Check whether t is a 2-element tuple where the first element is a string
  34.    and the second element is None.
  35.    '''
  36.     assert isinstance(t, tuple) and len(t) == 2 and isinstance(t[0], str) \
  37.            and t[1] is None, \
  38.            '{0} should return tuple of (str, NoneType), but returned \
  39.           {1}.'.format(func_name, t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement