utils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:mizani 作者: has2k1 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号