pysorting.utils

Exceptions

InvalidElementTypeError

Custom exception raised when elements are not strings or lists of strings.

NonUniformTypeError

Custom exception raised when elements are not strings or lists of strings.

InvalidAscendingTypeError

Custom exception raised when 'ascending' is not a boolean.

Functions

timer(func)

This function is used as a wrapper to time sorting function. It prints the time

sorting_time(sorting_function, data)

Returns the time taken to sort a function.

find_fastest_sorting_function(data, *sorting_functions)

Finds the fastest sorting function based on execution time.

is_sorted(lst[, ascending])

Checks if a list is sorted in ascending or descending order.

validate_list_elements(elements)

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: Exception

Custom 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: Exception

Custom 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: Exception

Custom 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.

pysorting.utils.validate_list_elements(elements)[source]

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.