MoreUtilspy
is a Python utility package designed to handle a variety of text, number, and data transformations. It includes features for converting between different formats (e.g., numbers, dates, Roman numerals), working with text (e.g., anagrams, palindromes), and handling JSON/CSV conversions.
To install MoreUtilspy
, use pip:
pip install MoreUtilspy
After installation, you can import and use the functions directly:
from MoreUtilspy import text_to_number, is_palindrome
This module provides functions for converting numbers, dates, bytes, and more.
Converts a textual representation of a number into its numerical value.
Example:
text_to_number("one hundred twenty-three") # Returns: 123
Converts a number to its textual representation.
Example:
number_to_text(123) # Returns: "one hundred twenty-three"
Converts an integer to a Roman numeral.
Example:
int_to_roman(2024) # Returns: "MMXXIV"
Converts a Roman numeral to an integer.
Example:
roman_to_int("MMXXIV") # Returns: 2024
Converts a snake_case string to camelCase.
Example:
snake_to_camel("hello_world") # Returns: "helloWorld"
Converts a camelCase string to snake_case.
Example:
camel_to_snake("helloWorld") # Returns: "hello_world"
Converts seconds into a human-readable format.
Example:
seconds_to_text(3665) # Returns: "1 hours, 1 minutes, 5 seconds"
Converts a text representation of time to seconds.
Example:
text_to_seconds("1 hour, 1 minute, 5 seconds") # Returns: 3665
Converts a date in YYYY-MM-DD
format to a human-readable text.
Example:
date_to_text("2024-01-01") # Returns: "January 1, 2024"
Converts a text representation of a date into YYYY-MM-DD
format.
Example:
text_to_date("January 1 2024") # Returns: "2024-01-01"
Converts bytes into a human-readable string.
Example:
bytes_to_text(10240) # Returns: "10.00 KB"
Converts a string representation of file size into bytes.
Example:
text_to_bytes("10 KB") # Returns: 10240
This module contains utilities for working with text strings, including palindromes, anagrams, and generating random passwords.
Checks if a string is a palindrome.
Example:
is_palindrome("racecar") # Returns: True
Checks if two strings are anagrams.
Example:
are_anagrams("listen", "silent") # Returns: True
Counts the number of vowels in a string.
Example:
count_vowels("hello world") # Returns: 3
Counts the number of consonants in a string.
Example:
count_consonants("hello world") # Returns: 7
Reverses the words in a string.
Example:
reverse_words("hello world") # Returns: "olleh dlrow"
Reverses a string.
Example:
reverse_string("hello") # Returns: "olleh"
Removes duplicate characters from a string.
Example:
remove_duplicates("mississippi") # Returns: "misp"
Checks if a string contains all letters of the alphabet.
Example:
is_pangram("The quick brown fox jumps over the lazy dog") # Returns: True
Calculates the Levenshtein distance (edit distance) between two strings.
Example:
levenshtein_distance("kitten", "sitting") # Returns: 3
Generates a random password of the specified length.
Example:
generate_password(16) # Returns: A 16-character random password
Converts JSON data to CSV and writes it to a file.
Example:
json_to_csv(json_data, "output.csv")
Converts a CSV file into JSON format.
Example:
data = csv_to_json("input.csv")
Here are a few quick examples to demonstrate how to use MoreUtilspy
:
from MoreUtilspy import text_to_number, is_palindrome, generate_password
# Convert text to number
print(text_to_number("one hundred twenty-three")) # Output: 123
# Check if a string is a palindrome
print(is_palindrome("A man a plan a canal Panama")) # Output: True
# Generate a random password
print(generate_password(16)) # Output: A randomly generated password
MoreUtilspy
is open source and licensed under the MIT License.