pysorting.utils
Exceptions
Custom exception raised when elements are not strings or lists of strings. |
|
Custom exception raised when elements are not strings or lists of strings. |
|
Custom exception raised when 'ascending' is not a boolean. |
Functions
|
This function is used as a wrapper to time sorting function. It prints the time |
|
Returns the time taken to sort a function. |
|
Finds the fastest sorting function based on execution time. |
|
Checks if a list is sorted in ascending or descending order. |
|
Validates if all elements in a list are either all numerical (int or float) |
Module Contents
- exception pysorting.utils.InvalidElementTypeError(message='All elements must be either a string or a list of strings.')[source]
Bases:
ExceptionCustom exception raised when elements are not strings or lists of strings.
- message = 'All elements must be either a string or a list of strings.'
- exception pysorting.utils.NonUniformTypeError(message='Elements are not of the same type.')[source]
Bases:
ExceptionCustom exception raised when elements are not strings or lists of strings.
- message = 'Elements are not of the same type.'
- exception pysorting.utils.InvalidAscendingTypeError(message="The parameter 'ascending' must be a boolean value.")[source]
Bases:
ExceptionCustom exception raised when ‘ascending’ is not a boolean.
- message = "The parameter 'ascending' must be a boolean value."
- pysorting.utils.timer(func)[source]
This function is used as a wrapper to time sorting function. It prints the time
- Parameters:
func (_type_) – _description_
- pysorting.utils.sorting_time(sorting_function, data)[source]
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).
- pysorting.utils.find_fastest_sorting_function(data, *sorting_functions)[source]
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).
- pysorting.utils.is_sorted(lst, ascending=True)[source]
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.