<commit_before>"""Create a function to insertion-sort an iterable."""
from collections import Iterable


def insertion_sort(lst):
    """Insertion sort an iterable."""
    if isinstance(lst, Iterable):
        for idx in range(1, len(lst)):
            current = lst[idx]
            index = idx
            while index > 0 and lst[index - 1] > current:
                lst[index] = lst[index - 1]
                index -= 1
            lst[index] = current
        return lst
    else:
        raise TypeError("You cannot insertion_sort a non-iterable.")


# if __name__ == "__main__":
#     """Calculate the runtime for binary searches in the BST."""
#     import timeit
#     lst_1 = [50, 45, 60, 1, -59, 55, 70, -75, 65, 20, 48, 49, 0, 10, 25]
#     sortit = insertion_sort(lst_1)

#     sort_time = timeit.timeit(
#         stmt="balanced.search(75)",
#         setup="from __main__ import balanced",
#         number=1000
#     ) * 1000
#     unbal = timeit.timeit(
#         stmt="unbalanced.search(75)",
#         setup="from __main__ import unbalanced",
#         number=1000
#     ) * 1000
#     print("It takes {} microseconds to find 75 in a balanced tree, and {} microseconds to find 75 in an unbalanced tree".format(bal, unbal))

#     in_o = timeit.timeit(
#         stmt="balanced.in_order_traversal()",
#         setup="from __main__ import balanced",
#         number=1000
#     ) * 1000
#     pre = timeit.timeit(
#         stmt="balanced.pre_order_traversal()",
#         setup="from __main__ import balanced",
#         number=1000
#     ) * 1000
#     post = timeit.timeit(
#         stmt="balanced.post_order_traversal()",
#         setup="from __main__ import balanced",
#         number=1000
#     ) * 1000
#     breadth = timeit.timeit(
#         stmt="balanced.breadth_first_traversal()",
#         setup="from __main__ import balanced",
#         number=1000
#     ) * 1000

#     print("It takes {} microseconds to traverse tree in order\n It takes {} microseconds to traverse tree preorder\n It takes {} microseconds to traverse tree postorder\n It takes {} microseconds to traverse tree in breadth first\n ".format(in_o, pre, post, breadth))<commit_msg>adding if name == main block<commit_after>"""Create a function to insertion-sort an iterable."""


def insertion_sort(lst):
    """Insertion sort an iterable."""
    if isinstance(lst, list):
        for idx in range(1, len(lst)):
            current = lst[idx]
            index = idx
            while index > 0 and lst[index - 1] > current:
                lst[index] = lst[index - 1]
                index -= 1
            lst[index] = current
        return lst
    else:
        raise TypeError("You cannot insertion_sort a non-iterable.")


if __name__ == "__main__":
    """Calculate the runtime for binary searches in the BST."""
    import timeit
    import random
    lst_1 = [random.randint(-100, 100) for x in range(10000)]
    lst_2 = [1, 2, 3]
    lst_3 = [x for x in range(10000)][::-1]

    best_case = timeit.timeit(
        stmt="insertion_sort(lst_2)",
        setup="from __main__ import insertion_sort, lst_2",
        number=1000
    ) * 1000

    average_case = timeit.timeit(
        stmt="insertion_sort(lst_1)",
        setup="from __main__ import insertion_sort, lst_1",
        number=1000
    ) * 1000

    worst_case = timeit.timeit(
        stmt="insertion_sort(lst_3)",
        setup="from __main__ import insertion_sort, lst_3",
        number=1000
    ) * 1000

    print("Insertion sort's best case scenario takes {} microseconds.\n Insertion sort's average case scenario takes {} microseconds.\n Insertion sort's worst case scenario takes {} microseconds.".format(best_case, average_case, worst_case))
{'fraction_non_alphanumeric': 0.11794734013970984, 'fraction_numerical': 0.0400322407307899, 'mean_word_length': 2.49249530956848, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033324', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1107, 'n_words': 332}