首页 > 其他分享 >优雅代码try...except...

优雅代码try...except...

时间:2023-06-22 21:24:21浏览次数:34  
标签:... except value next try pass

try:
    from _heapq import *
except ImportError:
    pass

  

    # When n>=size, it's faster to use sorted()
    try:
        size = len(iterable)
    except (TypeError, AttributeError):
        pass
    else:
        if n >= size:
            return sorted(iterable, key=key)[:n]

  

    for order, it in enumerate(map(iter, iterables)):
        try:
            next = it.__next__
            value = next()
            h_append([key(value), order * direction, value, next])
        except StopIteration:
            pass
    _heapify(h)

  来自 heapq.py

 

标签:...,except,value,next,try,pass
From: https://www.cnblogs.com/sangern/p/17498357.html

相关文章