def len_or_approx(tree):
    "\n    Prefer approximate length if implemented. (It's cheaper.)\n    "
    try:
        return operator.length_hint(tree)
    except TypeError:
        return len(tree)
Prefer approximate length if implemented. (It's cheaper.)
def len_or_approx(tree):
    "\n    \n    "
    try:
        return operator.length_hint(tree)
    except TypeError:
        return len(tree)