MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunctiondifferentiate
>>> differentiate(lambda x: x**2, 2, 2) 2 >>> differentiate(lambda x: x**2 * x**4, 9, 2) 196830 >>> differentiate(lambda y:
maths/dual_number_automatic_differentiation.py:95
↓ 1 callersMethoddiffs
(self, i: int, j: int, visited: list[list[bool]])
matrix/count_islands_in_matrix.py:20
↓ 1 callersFunctiondigit_factorial_sum
Function to perform the sum of the factorial of all the digits in number >>> digit_factorial_sum(69.0) Traceback (most recent call last)
project_euler/problem_074/sol2.py:42
↓ 1 callersFunctiondigit_replacements
Returns all the possible families of digit replacements in a number which contains at least one repeating digit >>> digit_replacements(5
project_euler/problem_051/sol1.py:56
↓ 1 callersFunctiondigit_sum
Returns the sum of the digits of the number. >>> digit_sum(123) 6 >>> digit_sum(456) 15 >>> digit_sum(78910) 25
project_euler/problem_119/sol1.py:16
↓ 1 callersFunctiondigital_differential_analyzer_line
Draws a line between two points using the DDA algorithm. Args: - p1: Coordinates of the starting point. - p2: Coordinates of the end
graphics/digital_differential_analyzer_line.py:4
↓ 1 callersFunctiondigits_fifth_powers_sum
>>> digits_fifth_powers_sum(1234) 1300
project_euler/problem_030/sol1.py:27
↓ 1 callersFunctiondijkstra
(graph, v, src)
graphs/dijkstra_2.py:21
↓ 1 callersMethoddijkstra
Dijkstra algorithm Examples: >>> graph_test = Graph(3) >>> graph_test.add_edge(0, 1, 2) >>> graph_test.add_e
graphs/dijkstra_algorithm.py:277
↓ 1 callersMethoddijkstra
Function that implements Dijkstra's single source shortest path algorithm for a graph represented using adjacency matrix representati
graphs/dijkstra_alternate.py:49
↓ 1 callersFunctiondijkstras_two_stack_algorithm
DocTests >>> dijkstras_two_stack_algorithm("(5 + 3)") 8 >>> dijkstras_two_stack_algorithm("((9 - (2 + 9)) + (8 - 1))") 5 >>>
data_structures/stacks/dijkstras_two_stack_algorithm.py:40
↓ 1 callersFunctiondilation
Return dilated image >>> dilation(np.array([[True, False, True]]), np.array([[0, 1, 0]])) array([[False, False, False]]) >>> dila
digital_image_processing/morphological_operations/dilation_operation.py:40
↓ 1 callersFunctiondiophantine
Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the diophantine equation a*x + b*y = c has a solution (where x a
blockchain/diophantine_equation.py:6
↓ 1 callersFunctiondis_between_closest_in_strip
closest pair of points in strip Parameters : points, points_count, min_dis (list(tuple(int, int)), int, int) Returns : min_dis
divide_and_conquer/closest_pair_of_points.py:61
↓ 1 callersFunctiondis_between_closest_pair
brute force approach to find distance between closest pair points Parameters : points, points_count, min_dis (list(tuple(int, int)), int
divide_and_conquer/closest_pair_of_points.py:39
↓ 1 callersFunctiondiscrete_cosine_transform
Compute the Discrete Cosine Transform (DCT) basis matrix. Args: dct_filter_num: The number of DCT filters to generate. filte
machine_learning/mfcc.py:430
↓ 1 callersMethoddisplay
Displays the board without delay in a matplotlib plot to visually understand and track the ant. >>> _ = LangtonsAnt(WIDTH, H
cellular_automata/langtons_ant.py:86
↓ 1 callersMethoddisplay
Prints all the elements in the store.
other/least_recently_used.py:66
↓ 1 callersFunctiondisplay_billionaires
Display Forbes real-time billionaires in a rich table. Args: forbes_billionaires (list): Forbes top 10 real-time billionaires
web_programming/get_top_billionaires.py:82
↓ 1 callersFunctiondisplay_linked_list
Display the flattened linked list. Args: root (TreeNode | None): The root of the flattened linked list. Examples: >>> r
data_structures/binary_tree/flatten_binarytree_to_linkedlist.py:109
↓ 1 callersFunctiondo_benchmark
(number: int)
bit_manipulation/count_number_of_one_bits.py:69
↓ 1 callersMethoddot_product
(cls, row: list[int], column: list[int])
matrix/matrix_class.py:359
↓ 1 callersFunctiondouble_linear_search
Iterate through the array from both sides to find the index of search_item. :param array: the array to be searched :param search_ite
searches/double_linear_search.py:4
↓ 1 callersFunctiondouble_sort
This sorting algorithm sorts an array using the principle of bubble sort, but does it both from left to right and right to left. Hence, it's
sorts/double_sort.py:4
↓ 1 callersFunctiondownload_image
Download an image from a given URL by scraping the 'og:image' meta tag. Parameters: url: The URL to scrape. Returns: A
web_programming/instagram_pic.py:15
↓ 1 callersFunctiondownload_images_from_google_query
Searches google using the provided query term and downloads the images in a folder. Args: query : The image search term to be provi
web_programming/download_images_from_google_query.py:24
↓ 1 callersFunctiondownload_video
(url: str)
web_programming/instagram_video.py:13
↓ 1 callersFunctiondpll_algorithm
Returns the model if the formula is satisfiable, else ``None`` This has the following steps: 1. If every clause in clauses is ``True``
other/davis_putnam_logemann_loveland.py:285
↓ 1 callersFunctiondraw_cross
Draw a cross at the specified position and with the specified length.
fractals/vicsek.py:18
↓ 1 callersFunctiondraw_fractal_recursive
Recursively draw the Vicsek fractal at the specified position, with the specified length and depth.
fractals/vicsek.py:37
↓ 1 callersFunctiondraw_vicsek_fractal
Draw the Vicsek fractal at the specified position, with the specified length and depth.
fractals/vicsek.py:57
↓ 1 callersFunctiondutch_national_flag_sort
A pure Python implementation of Dutch National Flag sort algorithm. :param data: 3 unique integer values (e.g., 0, 1, 2) in an sequence :
sorts/dutch_national_flag_sort.py:33
↓ 1 callersFunctiondynamic_lucas_number
Returns the nth lucas number >>> dynamic_lucas_number(1) 1 >>> dynamic_lucas_number(20) 15127 >>> dynamic_lucas_number(0)
maths/lucas_series.py:34
↓ 1 callersFunctiondynamic_programming
(index: int)
dynamic_programming/minimum_tickets_cost.py:110
↓ 1 callersFunctionedit_distance
Edit distance algorithm is a string metric, i.e., it is a way of quantifying how dissimilar two strings are to one another. It is measured by
strings/edit_distance.py:1
↓ 1 callersFunctionelement_priority_queue
()
data_structures/queues/priority_queue_using_list.py:205
↓ 1 callersFunctioneliminate
Eliminate d from values[s]; propagate when values or places <= 2. Return values, except return False if a contradiction is detected.
data_structures/arrays/sudoku_solver.py:98
↓ 1 callersFunctionemails_from_url
This function takes url and return all valid urls
web_programming/emails_from_url.py:70
↓ 1 callersFunctionencode
Encode the given plaintext using the Playfair cipher. Takes the plaintext and the key as input and returns the encoded string. >>> encod
ciphers/playfair_cipher.py:83
↓ 1 callersFunctionencode
>>> encode("myname") [13, 25, 14, 1, 13, 5]
ciphers/a1z26.py:12
↓ 1 callersFunctionencode_to_morse
Encode a plaintext message into Morse code. Args: plaintext: The plaintext message to encode. Returns: The Morse code repres
ciphers/fractionated_morse_cipher.py:79
↓ 1 callersFunctionencrypt
Encrypt a message using a permutation cipher with block rearrangement using a key. Args: message (str): The plaintext message to be
ciphers/permutation_cipher.py:57
↓ 1 callersFunctionencrypt
>>> encrypt("Sos!") '... --- ... -.-.--' >>> encrypt("SOS!") == encrypt("sos!") True
ciphers/morse_code.py:25
↓ 1 callersFunctionencrypt
Encrypt a given `plaintext` (string) and `key` (string), returning the encrypted ciphertext. >>> encrypt("hello world", "coffee") 'j
ciphers/autokey.py:12
↓ 1 callersMethodencrypt
Function to encrypt text using pseudo-random numbers >>> Onepad().encrypt("") ([], []) >>> Onepad().encrypt([])
ciphers/onepad_cipher.py:6
↓ 1 callersMethodencrypt
>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.encrypt('testing hill cipher') 'WHXYJOLM9C6XT085LL'
ciphers/hill_cipher.py:120
↓ 1 callersMethodencrypt
Performs shifting of the plaintext w.r.t. the shuffled __key_list to create the encoded_message >>> ssc = ShuffledShiftCiphe
ciphers/shuffled_shift_cipher.py:149
↓ 1 callersFunctionencrypt_and_write_to_file
( message_filename: str, key_filename: str, message: str, block_size: int = DEFAULT_BLOCK_SIZE
ciphers/rsa_cipher.py:70
↓ 1 callersFunctionencrypt_fractionated_morse
Encrypt a plaintext message using Fractionated Morse Cipher. Args: plaintext: The plaintext message to encrypt. key: The encrypti
ciphers/fractionated_morse_cipher.py:95
↓ 1 callersFunctionencrypt_message
>>> encrypt_message('LFWOAYUISVKMNXPBDCRJTQEGHZ', 'Harshil Darji') 'Ilcrism Olcvs'
ciphers/simple_substitution_cipher.py:34
↓ 1 callersFunctionencrypt_message
encrypt_message =============== Encrypts a message using the trifid_cipher. Any punctuatuion chars that would be used should be
ciphers/trifid_cipher.py:124
↓ 1 callersFunctionencrypt_message
>>> encrypt_message('HDarji', 'This is Harshil Darji from Dharmaj.') 'Akij ra Odrjqqs Gaisq muod Mphumrs.'
ciphers/vigenere_cipher.py:20
↓ 1 callersFunctionencrypt_message
>>> encrypt_message(4545, 'The affine cipher is a type of monoalphabetic ' ... 'substitution cipher.') 'VL}p MM{I}p
ciphers/affine_cipher.py:38
↓ 1 callersFunctionencrypt_message
( message: str, key: tuple[int, int], block_size: int = DEFAULT_BLOCK_SIZE )
ciphers/rsa_cipher.py:39
↓ 1 callersFunctionencrypt_message
>>> encrypt_message(6, 'Harshil Darji') 'Hlia rDsahrij'
ciphers/transposition_cipher.py:25
↓ 1 callersFunctionencrypt_message
>>> encrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World") 'Pcssi Bidsm'
ciphers/mono_alphabetic_ciphers.py:31
↓ 1 callersMethodencrypt_string
input: 'content' of type string and 'key' of type int output: encrypted string 'content' if key not passed the method uses th
ciphers/xor_cipher.py:103
↓ 1 callersFunctionengine
(input_character)
hashes/enigma_machine.py:30
↓ 1 callersFunctionequality
Check the equality of ALL elements in an iterable >>> equality([1, 2, 3, 4]) False >>> equality([2, 2, 2, 2]) True >>> equali
project_euler/problem_047/sol1.py:59
↓ 1 callersFunctionerase
Erase element Split all nodes with values less into left, Split all nodes with values greater into right. Merge left, right
data_structures/binary_tree/treap.py:96
↓ 1 callersFunctionerosion
Return eroded image >>> erosion(np.array([[True, True, False]]), np.array([[0, 1, 0]])) array([[False, False, False]]) >>> eros
digital_image_processing/morphological_operations/erosion_operation.py:42
↓ 1 callersFunctionescape_velocity
Calculates the escape velocity needed to break free from a celestial body's gravitational field. The formula used is: v = sqrt(2
physics/escape_velocity.py:4
↓ 1 callersFunctionestimate_pi
Generates an estimate of the mathematical constant PI. See https://en.wikipedia.org/wiki/Monte_Carlo_method#Overview The estimate is gen
maths/pi_monte_carlo_estimation.py:24
↓ 1 callersFunctioneuclidean
Simple method for calculating the euclidean distance between two points, with type np.ndarray. Example: >>> a = np.array([1, 0,
computer_vision/haralick_descriptors.py:338
↓ 1 callersFunctionevaluate
Evaluate how similar the item is with the target by just counting each char in the right position >>> evaluate("Helxo Worlx", "Hello Worl
genetic_algorithm/basic_string.py:24
↓ 1 callersFunctionevaluate
Evaluate postfix expression using a stack. >>> evaluate(["0"]) 0.0 >>> evaluate(["-0"]) -0.0 >>> evaluate(["1"]) 1.0
data_structures/stacks/postfix_evaluation.py:64
↓ 1 callersFunctionevaluate_poly
Evaluate a polynomial f(x) at specified point x and return the value. Arguments: poly -- the coefficients of a polynomial as an iterable in o
maths/polynomial_evaluation.py:4
↓ 1 callersFunctioneven_tree
2 1 3 1 4 3 5 2 6 1 7 2 8 6 9 8 10 8 On removing edges (1,3) and (1,6), we can get the desired result 2.
graphs/even_tree.py:33
↓ 1 callersFunctionexact_prime_factor_count
>>> exact_prime_factor_count(51242183) 3
maths/hardy_ramanujanalgo.py:7
↓ 1 callersFunctionexample
Example for "how to use the neural network class and use the respected methods for the desired output". Calls the TwoHiddenLayerNeuralNet
neural_network/two_hidden_layers_neural_network.py:252
↓ 1 callersFunctionexample
()
neural_network/back_propagation_neural_network.py:177
↓ 1 callersFunctionexample_1
Example 1: figure-8 solution to the 3-body-problem This example can be seen as a test of the implementation: given the right initial c
physics/n_body_simulation.py:253
↓ 1 callersFunctionexample_2
Example 2: Moon's orbit around the earth This example can be seen as a test of the implementation: given the right initial conditions,
physics/n_body_simulation.py:277
↓ 1 callersFunctionexample_3
Example 3: Random system with many bodies. No doctest provided since this function does not have a return value.
physics/n_body_simulation.py:303
↓ 1 callersFunctionexchange_sort
Uses exchange sort to sort a list of numbers. Source: https://en.wikipedia.org/wiki/Sorting_algorithm#Exchange_sort >>> exchange_sort([5,
sorts/exchange_sort.py:1
↓ 1 callersMethodexecute
(self)
graphs/edmonds_karp_multiple_source_and_sink.py:71
↓ 1 callersFunctionexits_word
Return True if it's possible to search the word suffix starting from the word_index. >>> exits_word([["A"]], "B", 0, 0, 0, set()) Fa
backtracking/word_search.py:47
↓ 1 callersMethodexpand_block
Takes a bytestring-block of length 64, unpacks it to a list of integers and returns a list of 80 integers after some bit operations
hashes/sha1.py:78
↓ 1 callersFunctionexponential_moving_average
Yields exponential moving averages of the given stock prices. >>> tuple(exponential_moving_average(iter([2, 5, 3, 8.2, 6, 9, 10]), 3)) (2
financial/exponential_moving_average.py:15
↓ 1 callersFunctionexponential_search
Pure implementation of an exponential search algorithm in Python. For more information, refer to: https://en.wikipedia.org/wiki/Exponenti
searches/exponential_search.py:60
↓ 1 callersMethodextend
Appends each item to the end of the LinkedList. >>> linked_list = LinkedList() >>> linked_list.extend([]) >>> str(linked_list)
data_structures/linked_list/print_reverse.py:71
↓ 1 callersFunctionextended_euclid
Extended Euclid >>> extended_euclid(10, 6) (-1, 2) >>> extended_euclid(7, 5) (-2, 3)
maths/modular_division.py:112
↓ 1 callersFunctionextended_euclidean_algorithm
Extended Euclidean Algorithm. Finds 2 numbers a and b such that it satisfies the equation am + bn = gcd(m, n) (a.k.a Bezout's Identity)
maths/extended_euclidean_algorithm.py:20
↓ 1 callersFunctionextended_gcd
Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers x and y, then d = gcd(a,b) >>> extended_gcd(10, 6)
maths/modular_division.py:82
↓ 1 callersFunctionextended_gcd
Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers x and y, then d = gcd(a,b) >>> extended_gcd(10, 6)
blockchain/diophantine_equation.py:74
↓ 1 callersMethodextract_min
Removes and returns the min element at top of priority queue. Examples: >>> priority_queue_test = PriorityQueue() >>
graphs/dijkstra_algorithm.py:108
↓ 1 callersFunctionfactorial
Calculate the factorial of specified number (n!). >>> import math >>> all(factorial(i) == math.factorial(i) for i in range(20)) True
maths/factorial.py:6
↓ 1 callersFunctionfactorial
>>> factorial(3) 6 >>> factorial(0) 1 >>> factorial(5) 120
maths/special_numbers/krishnamurthy_number.py:13
↓ 1 callersFunctionfactorial
Return the factorial of a number. :param n: Number to find the Factorial of. :return: Factorial of n. >>> import math >>> all(fa
data_structures/binary_tree/number_of_possible_binary_trees.py:59
↓ 1 callersFunctionfactorial
Find the factorial of a given number n
project_euler/problem_020/sol1.py:13
↓ 1 callersFunctionfast_inverse_sqrt
Compute the fast inverse square root of a floating-point number using the famous Quake III algorithm. :param float number: Input number
maths/fast_inverse_sqrt.py:10
↓ 1 callersFunctionfetch_bbc_news
(bbc_news_api_key: str)
web_programming/fetch_bbc_news.py:15
↓ 1 callersFunctionfetch_from_to
(start, end)
web_programming/co2_emission.py:26
↓ 1 callersFunctionfetch_jobs
(location: str = "mumbai")
web_programming/fetch_jobs.py:23
↓ 1 callersFunctionfetch_last_half_hour
()
web_programming/co2_emission.py:20
↓ 1 callersFunctionfetch_pharmacy_and_price_list
[summary] This function will take input of drug name and zipcode, then request to the BASE_URL site. Get the page data and scrape it to g
web_programming/fetch_well_rx_price.py:14
↓ 1 callersFunctionfibonacci
Computes the Fibonacci number for input n by iterating through n numbers and creating an array of ints using the Fibonacci formula. Retur
project_euler/problem_025/sol1.py:28
↓ 1 callersFunctionfibonacci
return F(n) >>> [fibonacci(i) for i in range(13)] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]
dynamic_programming/fast_fibonacci.py:13
↓ 1 callersFunctionfibonacci_digits_index
Computes incrementing Fibonacci numbers starting from 3 until the length of the resulting Fibonacci result is the input value n. Returns the
project_euler/problem_025/sol1.py:58
↓ 1 callersFunctionfibonacci_generator
A generator that produces numbers in the Fibonacci sequence >>> generator = fibonacci_generator() >>> next(generator) 1 >>> next
project_euler/problem_025/sol2.py:30
← previousnext →1,101–1,200 of 3,909, ranked by callers