Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

PythonUtilities

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:

Convert the number 42 to binary

binary_representation = bin(42) print(binary_representation)

Expected Output: "101010"

Convert the number 12 to binary

binary_representation = bin(12) print(binary_representation)

Expected Output: "1100"

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)

Expected Output: "once upon A Time, under the Starry Sky"

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]

Partition the list into chunks of 3

chunked_list = partition(my_list, 3) print(chunked_list)

Expected Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]

How to Use To use these functions, simply copy them into your Python project or import the m7a.py file.

Example of importing (if the file is in the same directory)

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))

About

A collection of small, reusable Python functions for common data manipulation tasks, including number conversion, string capitalization, and list partitioning.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages