def is_iterator(obj):
 from types import GeneratorType
 if isinstance(obj, GeneratorType):
  return True
 elif (not hasattr(obj, '__iter__')):
  return False
 else:
  return (iter(obj) is obj)

def is_iterator ( obj ) : from types import GeneratorType if isinstance ( obj , GeneratorType ) : return True elif ( not hasattr ( obj , '__iter__' ) ) : return False else : return ( iter ( obj ) is obj )
returns a boolean indicating if the object provided implements the iterator protocol .