Skip to content

Easy Strings

py_simple.easy_strings

Beginner-friendly helpers for common string operations.

count_words(text)

Counts the total number of words in a text string.

Parameters:

Name Type Description Default
text str

Text to process.

required

Returns:

Name Type Description
int int

Number of words found.

Example
from py_simple import count_words

result = count_words("Hello world! How are you?") # -> 5
import re

text = "Hello world! How are you?"
cleaned = re.sub(r"[^\w\s]", " ", text)
result = len(cleaned.split())

is_alphanumeric(text)

Returns True if text only contains letters and numbers, and False otherwise.

Parameters:

Name Type Description Default
text str

Text to check.

required

Returns:

Name Type Description
bool bool

True if text is alphanumeric, False otherwise.

Example
from py_simple import is_palindrome

result = is_alphanumeric("Something123")  # -> True
text = "Something123"
    if text.isalnum():
        return True
    else:
        return False

is_palindrome(text)

Returns True when text reads the same forwards and backwards.

Spaces, punctuation, and letter casing are ignored.

Parameters:

Name Type Description Default
text str

Text to check.

required

Returns:

Name Type Description
bool bool

True if text is a palindrome, False otherwise.

Example
from py_simple import is_palindrome

result = is_palindrome("Never odd or even")  # -> True
text = "Never odd or even"
cleaned = "".join(c.lower() for c in text if c.isalnum())
result = cleaned == cleaned[::-1]

remove_extra_spaces(text)

Removes leading, trailing, and repeated spaces from text.

Parameters:

Name Type Description Default
text str

Text to clean up.

required

Returns:

Name Type Description
str str

Text with extra whitespace removed.

Example
from py_simple import remove_extra_spaces

result = remove_extra_spaces("  hello   world  ")
# -> "hello world"
text = "  hello   world  "
result = " ".join(text.split())

to_kebab_case(text)

Converts text to kebab-case.

Parameters:

Name Type Description Default
text str

Text to convert.

required

Returns:

Name Type Description
str str

Text converted to kebab-case.

Example
from py_simple import to_kebab_case

result = to_kebab_case("Hello World")  # -> "hello-world"
import re

text = "Hello World"
cleaned = re.sub(r"[^\w\s]", " ", text)
result = "-".join(cleaned.lower().split())

to_snake_case(text)

Converts text to snake_case.

Parameters:

Name Type Description Default
text str

Text to convert.

required

Returns:

Name Type Description
str str

Text converted to snake_case.

Example
from py_simple import to_snake_case

result = to_snake_case("Hello World")  # -> "hello_world"
import re

text = "Hello World"
cleaned = re.sub(r"[^\w\s]", " ", text)
result = "_".join(cleaned.lower().split())