pysorting.utils =============== .. py:module:: pysorting.utils Exceptions ---------- .. autoapisummary:: pysorting.utils.InvalidElementTypeError pysorting.utils.NonUniformTypeError pysorting.utils.InvalidAscendingTypeError Functions --------- .. autoapisummary:: pysorting.utils.timer pysorting.utils.sorting_time pysorting.utils.find_fastest_sorting_function pysorting.utils.is_sorted pysorting.utils.validate_list_elements Module Contents --------------- .. py:exception:: InvalidElementTypeError(message='All elements must be either a string or a list of strings.') Bases: :py:obj:`Exception` Custom exception raised when elements are not strings or lists of strings. .. py:attribute:: message :value: 'All elements must be either a string or a list of strings.' .. py:exception:: NonUniformTypeError(message='Elements are not of the same type.') Bases: :py:obj:`Exception` Custom exception raised when elements are not strings or lists of strings. .. py:attribute:: message :value: 'Elements are not of the same type.' .. py:exception:: InvalidAscendingTypeError(message="The parameter 'ascending' must be a boolean value.") Bases: :py:obj:`Exception` Custom exception raised when 'ascending' is not a boolean. .. py:attribute:: message :value: "The parameter 'ascending' must be a boolean value." .. py:function:: timer(func) This function is used as a wrapper to time sorting function. It prints the time :param func: _description_ :type func: _type_ .. py:function:: sorting_time(sorting_function, data) Returns the time taken to sort a function. Parameters: - sorting_function: Sorting function to output the time taken to sort. - test_data: List to sort (same data will be passed to all functions). Returns: - A tuple (fastest_function, fastest_time). .. py:function:: find_fastest_sorting_function(data, *sorting_functions) Finds the fastest sorting function based on execution time. Parameters: - sorting_functions: List of sorting functions to compare. - test_data: List to sort (same data will be passed to all functions). Returns: - A tuple (fastest_function, fastest_time). .. py:function:: is_sorted(lst, ascending=True) Checks if a list is sorted in ascending or descending order. Parameters: - lst (list): The list to check. - ascending (bool): If True, checks for ascending order; otherwise, descending. Returns: - bool: True if the list is sorted in the specified order, False otherwise. .. py:function:: validate_list_elements(elements) Validates if all elements in a list are either all numerical (int or float) or all strings. Parameters: - elements (list): List of elements to validate. Returns: - bool: True if the list is valid, False otherwise.