def getfirst(iterable, exception=KeyError):
    """Get the first item from an iterable.
	This also works for generators.
	If the iterable is empty, exception is raised.
	If exception is None, None is returned instead.
	Warning: If iterable is not indexable (for example a set),
		 an arbitrary item is returned instead.
	"""
    try:
        return next(iter(iterable))
    except StopIteration:
        if exception:
            raise exception
        return None
