def validate_key(key, shape):
 (rows, cols) = shape
 if (not isinstance(key, tuple)):
  if (rows == 1):
   key = (slice(0, 1, None), key)
  elif (cols == 1):
   key = (key, slice(0, 1, None))
  else:
   raise IndexError('Invalid index/slice.')
 key = (format_slice(slc, dim) for (slc, dim) in zip(key, shape))
 return tuple(key)

def validate_key ( key , shape ) : ( rows , cols ) = shape if ( not isinstance ( key , tuple ) ) : if ( rows == 1 ) : key = ( slice ( 0 , 1 , None ) , key ) elif ( cols == 1 ) : key = ( key , slice ( 0 , 1 , None ) ) else : raise IndexError ( 'Invalid index/slice.' ) key = ( format_slice ( slc , dim ) for ( slc , dim ) in zip ( key , shape ) ) return tuple ( key )
check if the key is a valid index .