文章内容

2019/1/15 17:30:59,作 者: 黄兵

python bisect循环部分列表

现在有这样一种情况:有一个List,里面有很多数据,要求获取大于某一部分的数据,例如:

list = [1, 8, 9, 4, 6, 11, 25, 38, 14, 18, 58]

一些代码片段:

# 间隔5天
end = start - (5 * 24 * 60 * 60)
get_visit_time_line = conn.lrange('visit_time_line', 0, -1)

index = bisect.bisect_right(get_visit_time_line, end)

for item in get_visit_time_line:
    if float(item) > end:
        continue
    else:
        get_ip = conn.hget("time:" + item, "ip")
        get_url = conn.hget("time:" + item, "url")
        get_user_agent = conn.hget("time:" + item, "user_agent")

        index -= 1

未完待续。


参考资料:bisect — Array bisection algorithm¶

python bisect模块使用————二分法

一个有趣的python排序模块:bisect

分享到:

发表评论

评论列表