def first_element(obj):
"""
Return the first element of `obj`
Parameters
----------
obj : iterable
Should not be an iterator
Returns
-------
out : object
First element of `obj`. Raise a class:`StopIteration`
exception if `obj` is empty.
"""
if isinstance(obj, Iterator):
raise RuntimeError(
"Cannot get the first element of an iterator")
return next(iter(obj))
评论列表
文章目录