<jupyter_start><jupyter_text>Returns the sign of a value (-1, 0, or 1 for -ve, 0, or +ve)<jupyter_code>def sgn(x):
    if x < 0:
        return -1
    elif x > 0:
        return 1
    else:
        return 0<jupyter_output><empty_output><jupyter_text>Iterative implmentation of bisection method<jupyter_code>def bisection(f, left, right, dp):
    while round(left, dp) != round(right, dp):
        mid = (left + right) / 2
        left_val = f(left)
        mid_val = f(mid)
        right_val = f(right)
        if sgn(left_val) != sgn(mid_val):
            right = mid
        else:
            assert sgn(mid_val) != sgn(right_val)
            left = mid
    return round(left, dp)<jupyter_output><empty_output><jupyter_text>Test case<jupyter_code>import math

bisection(lambda x: x * math.exp(-x) - 0.25, 2.1, 2.3, 6)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12603062426383982, 'fraction_numerical': 0.02120141342756184, 'mean_word_length': 2.6956521739130435, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '588613', 'license': 'Unlicense', 'n_tokens_mistral': 338, 'n_tokens_neox': 320, 'n_words': 76, 'path': '2020-01/level2/leechristie/iterative_version.ipynb', 'repo_name': 'enzo-bc/user_group', 'size': '849'}