A collection of small, reusable Python functions for common data manipulation tasks, including number conversion, string capitalization, and list partitioning.
Functions This collection includes the following utility functions:
bin(decimal_num)
capitalize(input_string)
partition(numbers, size)
bin(decimal_num) Converts a decimal (base-10) integer into its binary (base-2) string representation. This function implements the repeated division-by-2 algorithm.
Parameters:
decimal_num (int): The integer you want to convert.
Returns:
(str): A string containing the binary equivalent of the input number.
Example:
binary_representation = bin(42) print(binary_representation)
binary_representation = bin(12) print(binary_representation)
capitalize(input_string) Capitalizes the first letter of each word in a string, with the exception of specific words. Words are converted to lowercase before processing, and any word starting with 'o', 'u', 's', 'n', or 'd' is ignored.
Parameters:
input_string (str): The string to be capitalized.
Returns:
(str): A new string with the specified capitalization rules applied.
Example:
my_sentence = "once upon a time, under the starry sky" capitalized_sentence = capitalize(my_sentence) print(capitalized_sentence)
partition(numbers, size) Splits a list into smaller, equal-sized chunks or sublists. The final chunk may be smaller if the total number of elements is not evenly divisible by the chunk size.
Parameters:
numbers (list): The list you want to partition.
size (int): The desired size of each chunk.
Returns:
(list): A new list of lists, where each inner list is a chunk of the original.
Example:
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
chunked_list = partition(my_list, 3) print(chunked_list)
How to Use To use these functions, simply copy them into your Python project or import the m7a.py file.
from m7a import bin, capitalize, partition
print(bin(255)) print(capitalize("see the BIG dog run")) print(partition([1, 1, 2, 3, 5, 8], 2))