These are just some of the functions that I wrote myself. I didn't write them for external use. I know that there are precompiled binary subroutines in Python that work thousands times faster. I wanted to write these basic functions myself just to prove that I can. That's all.
There's one thing however, that I like about these functions -- since they are open source, you can easily see how they work and customize them for your own purposes.
To use any of these .py files as a functions' library:
- Fork this repo or Download it as a ZIP file;
- Put necessary file into your working directory;
- In your project's .py file use
import filename
to import all functions from the file orfrom filename import functionname
to only import a specific function; - If you've imported the whole file you will have to use dot notation to call functions that it contains;
- If you've used the second notation to only import one function, you can call it buy its name like you would do to a normal function from your file;
# First method -- importing the whole file
import primes
primes.check(13)
# Second method -- importing a specific function from the file
from stringD import reverse
reverse("Hello, world!")
Here I will list all the files, functions inside them and their purposes so that you can know what they contain without having to actually look through each and every file. Filenames I will put in bold, functions and classes will be cursive.
- factorial --> returns factorial (n!) of given number;
- nPr --> returns number of permutations of n elements for r positions;
- nCr --> returns number of combinations of n elements for r positions;
- anagram --> returns list of every possible arrangement of a given string;
- find --> returns (a) list of divisors; (b) number of divisors; (c) sum of divisors of a given number;
- class Fist --> class that may be used to create and interact with final state machines that use binary-based input (string consisting of 0s and 1s);
- class Graph --> class that may be used to create and interact with undirected graphs where edges don't have values (every edge is as good a path as any other edge);
- unsorted --> returns unsorted list of numbers of given size and given range;
- lsum --> returns sum of a given list of numbers;
- _not --> returns the reverse of binary input;
- _and --> returns 1 if both inputs were 1, otherwise returns 0;
- _or --> returns 1 if either of two inputs were 1, otherwise returns 0;
- _xor --> returns 1 if two inputs were different, otherwise returns 0;
(Each of these methods work with inputs longer than one character, for example you can input 10010)
- power --> returns given number to the given positive power > 1;
- fib --> returns i-th number from Fibonacci sequence if i is positive, otherwise returns -1;
- mod --> returns True if given x is divisible by given y, otherwise returns False;
- intersect --> returns the intersection of two given lists or sets;
- coprimes --> returns list of coprimes of a given number;
- gcd --> returns greatest common divisor of two given numbers;
- floor --> returns rounded version of a given number (0.5 --> 1; 0.4 --> 0);
- additorial --> returns sum of all numbers below some given n, including n itself; additorial(3) = 3 + 2 + 1 = 6;
- divisors --> returns all proper divisors of n (excluding n);
- matadd --> returns sum of two given matrices;
- matnmul --> returns the result of multiplying matrix m by some number n;
- matmul --> returns the result of multiplying matrix m by matrix n;
- minor --> returns the minor of the given matrix;
- det --> returns a determinant of the given matrix;
- check --> returns True if number is prime, otherwise returns False;
- find --> returns list of prime numbers less than given limit;
- find_distincts --> returns (a) list of distinct prime divisors; (b) sum of distinct prime divisors of a given number;
- find_prime_factors --> returns list of prime factors of n;
- class Queue --> implementation of Queue datatype;
- binary --> returns index of the element in a given list if found, otherwise returns -1;
- linear --> returns index(s) of the element in a given list if found, otherwise returns -1;
- insertion --> returns sorted list of numbers;
- merge --> returns sorted list of numbers;
- bubble --> returns sorted list of numbers;
- class Stack --> implementation of Stack datatype;
- reverse --> returns reversed string;
- remove_repeats --> returns string without repetitions;
For any personal or business enquiries:
- Email: sharp.vik@gmail.com
- VK