MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

Methodis_private
(self)
web_programming/instagram_crawler.py:106
Functionis_pronic
# doctest: +NORMALIZE_WHITESPACE This functions takes an integer number as input. returns True if the number is pronic. >>> is_pronic
maths/special_numbers/pronic_number.py:13
Methodis_right
(self)
data_structures/binary_tree/binary_search_tree.py:125
Functionis_safe_prime
Checks if input number and (number - 1)/2 are prime. The smallest safe prime is 5, with the Germain prime is 2. >>> is_safe_prime(5) True
maths/germain_primes.py:41
Methodis_sorted
>>> Node(data='abc').is_sorted True >>> Node(data=2, ... left=Node(data=1.999), ... right=Node(data
data_structures/binary_tree/is_sorted.py:48
Functionis_spain_national_id
Spain National Id is a string composed by 8 numbers plus a letter The letter in fact is not part of the ID, it acts as a validator, check
strings/is_spain_national_id.py:5
Methodis_square
(self)
matrix/matrix_class.py:147
Functionis_strong_password
This will check whether a given password is strong or not. The password must be at least as long as the provided minimum length, and it must
other/password.py:54
Methodis_sum_node
>>> root = Node(3) >>> root.is_sum_node True >>> root.left = Node(1) >>> root.is_sum_node False
data_structures/binary_tree/is_sum_tree.py:46
Functionis_sum_subset
>>> is_sum_subset([2, 4, 6, 8], 5) False >>> is_sum_subset([2, 4, 6, 8], 14) True
dynamic_programming/sum_of_subset.py:1
Methodis_sum_tree
>>> BinaryTree.build_a_tree().is_sum_tree False >>> BinaryTree.build_a_sum_tree().is_sum_tree True
data_structures/binary_tree/is_sum_tree.py:99
Functionis_symmetric_tree
Check if a binary tree is symmetric (i.e., a mirror of itself). Parameters: tree: The root node of the binary tree. Returns: bo
data_structures/binary_tree/symmetric_tree.py:104
Functionis_valid_sudoku_board
This function validates (but does not solve) a sudoku board. The board may be valid but unsolvable. >>> is_valid_sudoku_board([ ...
matrix/validate_sudoku_board.py:28
Methodis_verified
(self)
web_programming/instagram_crawler.py:102
Methodivi
Ideal vegetation index https://www.indexdatabase.de/db/i-single.php?id=276 b=intercept of vegetation line a=soil line
digital_image_processing/index_calculation.py:398
Functionjacobi_iteration_method
Jacobi Iteration Method: An iterative algorithm to determine the solutions of strictly diagonally dominant system of linear equations
linear_algebra/jacobi_iteration_method.py:13
Functionjob_sequencing_with_deadlines
Function to find the maximum profit by doing jobs in a given time frame Args: jobs [list]: A list of tuples of (job_id, deadline, pr
scheduling/job_sequencing_with_deadline.py:1
Functionjoin
Joins a list of strings using a separator and returns the result. :param separator: Separator to be used for joining the
strings/join.py:6
Functionjosephus_iterative
Solve the Josephus problem for num_people and a step_size iteratively. Args: num_people (int): The number of people in the circle.
maths/josephus_problem.py:100
Functionjuggler_sequence
>>> juggler_sequence(0) Traceback (most recent call last): ... ValueError: Input value of [number=0] must be a positive integer
maths/juggler_sequence.py:15
Functionkelvin_to_celsius
Convert a given value from Kelvin to Celsius and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
conversions/temperature_conversions.py:170
Functionkelvin_to_fahrenheit
Convert a given value from Kelvin to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
conversions/temperature_conversions.py:194
Functionkelvin_to_rankine
Convert a given value from Kelvin to Rankine and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
conversions/temperature_conversions.py:218
Functionkg_v
Least common multiple input: two positive integer 'number1' and 'number2' returns the least common multiple of 'number1' and 'number2'
maths/primelib.py:447
Functionkinetic_energy
Calculate kinetic energy. The kinetic energy of a non-rotating object of mass m traveling at a speed v is ½mv² >>> kinetic_energy(10,10
physics/kinetic_energy.py:21
Functionknapsack
Function description is as follows- :param weights: Take a list of weights :param values: Take a list of profits corresponding to the wei
knapsack/recursive_approach_knapsack.py:20
Functionknapsack
Returns the maximum value that can be put in a knapsack of a capacity cap, whereby each weight w has a specific value val with option to
knapsack/knapsack.py:10
Functionkrusk
Sort edges on the basis of distance
graphs/basic_graphs.py:350
Methodkruskal
Details: https://en.wikipedia.org/wiki/Kruskal%27s_algorithm Example: >>> g1 = GraphUndirectedWeighted[int]() >>> g1
graphs/minimum_spanning_tree_kruskal2.py:66
Functionkth_largest_element
Finds the kth largest element in a list. Should deliver similar results to: ```python def kth_largest_element(arr, position):
data_structures/arrays/kth_largest_element.py:44
Functionkth_number
Return the kth smallest number in lst. >>> kth_number([2, 1, 3, 4, 5], 3) 3 >>> kth_number([2, 1, 3, 4, 5], 1) 1 >>> kth_numb
divide_and_conquer/kth_order_statistic.py:26
Functionkth_permutation
Finds k'th lexicographic permutation (in increasing order) of 0,1,2,...n-1 in O(n^2) time. Examples: First permutation is alway
maths/kth_lexicographic_permutation.py:1
Functionkullback_leibler_divergence
Calculate the Kullback-Leibler divergence (KL divergence) loss between true labels and predicted probabilities. KL divergence loss quant
machine_learning/loss_functions.py:632
Methodlabels
(self)
neural_network/input_data.py:189
Functionlamberts_ellipsoidal_distance
Calculate the shortest distance along the surface of an ellipsoid between two points on the surface of earth given longitudes and latitudes
geodesy/lamberts_ellipsoidal_distance.py:10
Functionlargest_pow_of_two_le_num
Return the largest power of two less than or equal to a number. >>> largest_pow_of_two_le_num(0) 0 >>> largest_pow_of_two_le_num(1)
bit_manipulation/largest_pow_of_two_le_num.py:22
Functionlargest_rectangle_area
Inputs an array of integers representing the heights of bars, and returns the area of the largest rectangle that can be formed >>> large
data_structures/stacks/largest_rectangle_histogram.py:1
Functionlargest_square_area_in_matrix_bottom_up_space_optimization
Function updates the largest_square_area, using bottom up approach. with space optimization. >>> largest_square_area_in_matrix_bottom_up
matrix/largest_square_area_in_matrix.py:153
Functionlargest_square_area_in_matrix_top_down_approch
Function updates the largest_square_area[0], if recursive call found square with maximum area. We aren't using dp_array here, so the tim
matrix/largest_square_area_in_matrix.py:46
Functionlargest_square_area_in_matrix_top_down_approch_with_dp
Function updates the largest_square_area[0], if recursive call found square with maximum area. We are using dp_array here, so the time c
matrix/largest_square_area_in_matrix.py:82
Methodlast
return last element >>> d = LinkedDeque() >>> d.add_last('A').last() 'A' >>> d.add_last('B').last() 'B'
data_structures/linked_list/deque_doubly.py:75
Functionleaky_rectified_linear_unit
Implements the LeakyReLU activation function. Parameters: vector (np.ndarray): The input array for LeakyReLU activation.
neural_network/activation_functions/leaky_rectified_linear_unit.py:12
Methodlength
(self)
machine_learning/sequential_minimum_optimization.py:400
Functionlength_conversion
Conversion between length units. >>> length_conversion(4, "METER", "FEET") 13.12336 >>> length_conversion(4, "M", "FT") 13
conversions/length_conversion.py:58
Functionlength_conversion
Conversion between astronomical length units. >>> length_conversion(1, "meter", "kilometer") 0.001 >>> length_conversion(1, "meter",
conversions/astronomical_length_scale_conversion.py:46
Methodlevel
:return: Number of forward references >>> node = Node("Key", 2) >>> node.level 0 >>> node.forward.append(Nod
data_structures/linked_list/skip_list.py:34
Functionliouville_lambda
This functions takes an integer number as input. returns 1 if n has even number of prime factors and -1 otherwise. >>> liouville_lambda(1
maths/liouville_lambda.py:14
Functionlist_of_submasks
Args: mask : number which shows mask ( always integer > 0, zero does not have any submasks ) Returns: all_submas
dynamic_programming/iterating_through_submasks.py:12
Functionlog_likelihood
(x, y, weights)
machine_learning/logistic_regression.py:106
Functionlogical_left_shift
Take in 2 positive integers. 'number' is the integer to be logically left shifted 'shift_amount' times. i.e. (number << shift_amount)
bit_manipulation/binary_shifts.py:6
Functionlogical_right_shift
Take in positive 2 integers. 'number' is the integer to be logically right shifted 'shift_amount' times. i.e. (number >>> shift_amount)
bit_manipulation/binary_shifts.py:36
Functionlogin_using_recaptcha
(request)
web_programming/recaptcha_verification.py:51
Functionlongest_common_substring
Finds the longest common substring between two strings. >>> longest_common_substring("", "") '' >>> longest_common_substring("a","")
dynamic_programming/longest_common_substring.py:13
Functionlongest_increasing_subsequence_length
>>> longest_increasing_subsequence_length([2, 5, 3, 7, 11, 8, 10, 13, 6]) 6 >>> longest_increasing_subsequence_length([]) 0 >>> l
dynamic_programming/longest_increasing_subsequence_o_nlogn.py:20
Functionlongest_palindromic_subsequence
This function returns the longest palindromic subsequence in a string >>> longest_palindromic_subsequence("bbbab") 4 >>> longest_pali
dynamic_programming/longest_palindromic_subsequence.py:11
Functionlongest_prefix
Prefix-function use case Finding longest prefix which is suffix as well >>> longest_prefix("aabcdaabc") 4 >>> longest_prefix("as
strings/prefix_function.py:44
Functionlongest_subsequence
Some examples >>> longest_subsequence([10, 22, 9, 33, 21, 50, 41, 60, 80]) [10, 22, 33, 50, 60, 80] >>> longest_subsequence([4, 8, 7
dynamic_programming/longest_increasing_subsequence_iterative.py:21
Functionlongest_subsequence
Some examples >>> longest_subsequence([10, 22, 9, 33, 21, 50, 41, 60, 80]) [10, 22, 33, 41, 60, 80] >>> longest_subsequence([4, 8, 7
dynamic_programming/longest_increasing_subsequence.py:19
Functionlower
Will convert the entire string to lowercase letters >>> lower("wow") 'wow' >>> lower("HellZo") 'hellzo' >>> lower("WHAT")
strings/lower.py:1
Functionlower_upper_decomposition
Perform LU decomposition on a given matrix and raises an error if the matrix isn't square or if no such decomposition exists >>> matrix
linear_algebra/lu_decomposition.py:25
Methodm_savi
Modified Soil Adjusted Vegetation Index https://www.indexdatabase.de/db/i-single.php?id=44 :return: index
digital_image_processing/index_calculation.py:440
Functionmae
Examples(rounded for precision): >>> actual = [1,2,3];predict = [1,4,3] >>> float(np.around(mae(predict,actual),decimals = 2)) 0.67
machine_learning/scoring_functions.py:19
Functionmain
()
maths/sum_of_arithmetic_series.py:16
Functionmain
>>> key = get_random_key() >>> msg = "This is a test!" >>> decrypt_message(key, encrypt_message(key, msg)) == msg True
ciphers/affine_cipher.py:85
Functionmajority_vote
>>> majority_vote([1, 2, 2, 3, 1, 3, 2], 3) [2] >>> majority_vote([1, 2, 2, 3, 1, 3, 2], 2) [] >>> majority_vote([1, 2, 2, 3, 1,
other/majority_vote_algorithm.py:11
Functionmake_allpass
Creates an all-pass filter >>> filter = make_allpass(1000, 48000) >>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHITESPAC
audio_filters/butterworth_filter.py:104
Functionmake_asymmetric_tree
r""" Create an asymmetric tree for testing. The tree looks like this: 1 / \ 2 2 / \ / \ 3 4
data_structures/binary_tree/symmetric_tree.py:71
Functionmake_bandpass
Creates a band-pass filter >>> filter = make_bandpass(1000, 48000) >>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHITESPA
audio_filters/butterworth_filter.py:73
Functionmake_highpass
Creates a high-pass filter >>> filter = make_highpass(1000, 48000) >>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHITESPA
audio_filters/butterworth_filter.py:43
Functionmake_highshelf
Creates a high-shelf filter >>> filter = make_highshelf(1000, 48000, 6) >>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHI
audio_filters/butterworth_filter.py:200
Functionmake_linked_list
Creates a Linked List from the elements of the given sequence (list/tuple) and returns the head of the Linked List. >>> make_linked_list
data_structures/linked_list/from_sequence.py:23
Functionmake_lowpass
Creates a low-pass filter >>> filter = make_lowpass(1000, 48000) >>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHITESPACE
audio_filters/butterworth_filter.py:13
Functionmake_lowshelf
Creates a low-shelf filter >>> filter = make_lowshelf(1000, 48000, 6) >>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHITE
audio_filters/butterworth_filter.py:163
Functionmake_peak
Creates a peak filter >>> filter = make_peak(1000, 48000, 6) >>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHITESPACE
audio_filters/butterworth_filter.py:131
Functionmake_symmetric_tree
r""" Create a symmetric tree for testing. The tree looks like this: 1 / \ 2 2 / \ / \ 3 4
data_structures/binary_tree/symmetric_tree.py:38
Functionmake_tree
>>> make_tree().val 3
data_structures/binary_tree/diff_views_of_binary_tree.py:22
Functionmalus_law
>>> round(malus_law(10,45),2) 5.0 >>> round(malus_law(100,60),2) 25.0 >>> round(malus_law(50,150),2) 37.5 >>> round(malus
physics/malus_law.py:40
Functionmanhattan_distance
Expectts two list of numbers representing two points in the same n-dimensional space https://en.wikipedia.org/wiki/Taxicab_geometry
maths/manhattan_distance.py:1
Functionmanhattan_distance_one_liner
Version with one liner >>> manhattan_distance_one_liner([1,1], [2,2]) 2.0 >>> manhattan_distance_one_liner([1.5,1.5], [2,2]) 1.0
maths/manhattan_distance.py:81
Functionmanual_accuracy
(predict, actual)
machine_learning/scoring_functions.py:138
Functionmass_from_energy
Calculates the Mass equivalence of the Energy using m = E/c² in SI units kg from Energy in J. energy (float): Mass of body. Usage e
physics/mass_energy_equivalence.py:49
Functionmat_bin_search
This function loops over a 2d matrix and calls binarySearch on the selected 1d array and returns [-1, -1] is it do not exist value : valu
matrix/binary_search_matrix.py:25
Functionmatch_word_pattern
Determine if a given pattern matches a string using backtracking. pattern: The pattern to match. input_string: The string to match again
backtracking/match_word_pattern.py:1
Functionmatching_min_vertex_cover
APX Algorithm for min Vertex Cover using Matching Approach @input: graph (graph stored in an adjacency list where each vertex is
graphs/matching_min_vertex_cover.py:11
Functionmax_difference
We are given an array A[1..n] of integers, n >= 1. We want to find a pair of indices (i, j) such that 1 <= i <= j <= n and A[j] - A[i] is
divide_and_conquer/max_difference_pair.py:1
Methodmax_parts
Return the maximum number of parts that circle can be divided into if cut 'num_cuts' times. >>> circle = Circle(5) >
geometry/geometry.py:142
Functionmax_product_subarray
Returns the maximum product that can be obtained by multiplying a contiguous subarray of the given integer list `numbers`. Example:
dynamic_programming/max_product_subarray.py:1
Functionmax_sum_bst
The solution traverses a binary tree to find the maximum sum of keys in any subtree that is a Binary Search Tree (BST). It uses recursion
data_structures/binary_tree/maximum_sum_bst.py:17
Functionmaximum_kinetic_energy
Calculates the maximum kinetic energy of emitted electron from the surface. if the maximum kinetic energy is zero then no electron will be
physics/photoelectric_effect.py:27
Functionmaximum_non_adjacent_sum
Find the maximum non-adjacent sum of the integers in the nums input list >>> maximum_non_adjacent_sum([1, 2, 3]) 4 >>> maximum_non_a
dynamic_programming/max_non_adjacent_sum.py:6
Functionmbd
This value is Negative, if the model underpredicts, positive, if it overpredicts. Example(rounded for precision): Here the model ov
machine_learning/scoring_functions.py:109
Functionmd5_me
Returns the 32-char MD5 hash of a given message. Reference: https://en.wikipedia.org/wiki/MD5#Algorithm Arguments: message {[st
hashes/md5.py:297
Functionmean_absolute_error
Return sum of square error for error calculation :param predicted_y : contains the output of prediction (result vector) :param original_y
machine_learning/linear_regression.py:113
Functionmean_absolute_percentage_error
Calculate the Mean Absolute Percentage Error between y_true and y_pred. Mean Absolute Percentage Error calculates the average of the absolut
machine_learning/loss_functions.py:439
Functionmean_squared_logarithmic_error
Calculate the mean squared logarithmic error (MSLE) between ground truth and predicted values. MSLE measures the squared logarithmic dif
machine_learning/loss_functions.py:403
Functionmedian
One common application of Quickselect is finding the median, which is the middle element (or average of the two middle elements) in a sorted
searches/quick_select.py:65
Functionmedian
Find median of a list of numbers. Wiki: https://en.wikipedia.org/wiki/Median >>> median([0]) 0 >>> median([4, 1, 3, 2]) 2.5
maths/average_median.py:4
Functionmedian
Calculate the median of a sorted matrix. Args: matrix: A 2D matrix of integers. Returns: The median value of the matrix
matrix/median_matrix.py:6
Methodmedium_tree
Return a medium binary tree with 3 nodes. >>> binary_tree = BinaryTree.medium_tree() >>> len(binary_tree) 7 >
data_structures/binary_tree/basic_binary_tree.py:57
Functionmerge
Return a sorted array. >>> merge([10,9,8,7,6,5,4,3,2,1]) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> merge([1,2,3,4,5,6,7,8,9,10]) [1, 2, 3, 4
sorts/recursive_mergesort_array.py:8
← previousnext →3,301–3,400 of 3,909, ranked by callers