recipe-577515.py 文件源码

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

项目:code 作者: ActiveState 项目源码 文件源码
def __getitem__(self, key):
        bounds, values = self._bounds, self._values
        if hasattr(key, 'start') and hasattr(key, 'stop'):
            # we are indexing with an interval. we only return the value
            # if that interval is contained within one of our intervals.
            start, stop = key.start, key.stop
            lindex = bisect_right(bounds, start) if start is not None else 0
            rindex = (bisect_left(bounds, stop)
                      if stop is not None else len(bounds))
            if lindex != rindex:
                raise KeyError(key)
            return values[lindex]
        else:
            # We are indexing with a single element.
            result = values[bisect_right(bounds, key)]
            if result is self.nothing:
                raise KeyError(key)
            return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号