Reverses a string.
Allows you to loop through a dictionary while having access to its value, key and current loop index. Example:
my_dict = {'a':1, 'b':2, 'c':3}
for key, val, i in loop_dict(my_dict):
# Stuff here
Returns the nth root of the number you provide.
Filters a list based on whether elements contain a specific string.
Filters a list based on a specific condition.
How to use:
condition property is a string. If you wanted to filter a list based on whether the element (suppose is going to be an integer) was even or not, you would:
lst = [0,1,2,3,4,5,6,7,8,9,10]
new_lst = usefulib.filter_by_condition(lst, "i % 2 == 0")
The variable i
is the element.
Generates a random string using ASCII chars, digits and special chars.
Generates a UUID using version 4 by default but you can choose.
If you are printing a lot of data, you can use this method to write the output to log file.
This takes a string as input, hashes it using the SHA-256 algorithm, and returns the hexadecimal representation of the hash value.
Converts from denary to ternary
This calculates and returns the nth Fibonacci number using recursion.
This checks whether a given string is a palindrome, meaning it reads the same backward as forward.
Converts from one base to another (base 2-16).
Sorts the numbers from numlist[start] to numlist[end] using the quicksort algorithm.