String functions for Python 3, inspired by similar Lotus Domino @functions



Install the latest release from PyPI:

pip install str_util


All functions are available directly off the str_util package. You may choose to import individual functions by name, or import all.

from str_util import word, is_string

def foo(value):
    if is_string( value ):
        return word(value,1)
    return "not a string"



str_util.to_string(value) Convert a value to a string.
str_util.to_list(value) Convert a value to a list.
str_util.implode(strings[, separator]) Concatenate all member of a list into a single string by a separating delimiter.


str_util.is_string(value) Tests the value to determine whether it is a string.
str_util.is_list(value) Tests the value to determine whether it is a list.
str_util.is_empty(value) Return true is value is empty or only contains whitespace
str_util.is_member(source_list, search_list) Check if the source_list is a subset of the search_list
str_util.is_equal(value1, value2[, ignore_case]) Compare two values and returns trues if they are equal
str_util.contains(value, substrings[, …]) Determine if a string contains any of the substrings
str_util.contains_all(value, substrings[, …]) Determine if a string contains all of the substring substrings, string2[, ignore_case]) Compares two strings, pattern[, ignore_case]) Matches a string with a pattern


str_util.trim(value) Removes leading, trailing, and redundant spaces/whitespace from a text string, or from each element of a text list.
str_util.propercase(value) Converts the words in a string to proper­name capitalization: the first letter of each word becomes uppercase, the rest become lowercase.
str_util.lowercase(value) Converts a string or list of strings to lowercase.
str_util.replace_substring(source, fromlist, …) Replaces specific words in a string or list with new words


str_util.left(value, find[, ignore_case]) Searches a string from left to right and returns the leftmost characters of the string.
str_util.left_back(value, find[, ignore_case]) As left() but counts/searches from the back
str_util.right(value, find[, ignore_case]) Searches a string from left to right and returns the rightmost characters of the string.
str_util.right_back(value, find[, ignore_case]) Searches a string from the back (right to left) and returns the rightmost characters.
str_util.word(value, number[, separator]) Returns a specified word from a text string.

List operations

str_util.unique(source_list[, ignore_case]) Removes duplicate values from a list of strings by returning only the first occurrence of each member of the list.
str_util.index_of(value, substring[, …]) Find the first occurrence of the substring and return the position, If not found, return -1 First character in the string(first element in list has position = 0
str_util.replace(source, fromlist, tolist[, …]) Performs a search-and-replace operation on a list.
str_util.diff(list1, list2[, ignore_case]) Remove elements in list2 from list1
str_util.union(list1, list2) Adds two list
str_util.intersection(list1, list2[, …]) Intersection of the two given list’s is a list which consists of all the elements which are common to both list1 and list2.
str_util.sort(source_list[, ignore_case, …])
param list source_list:
 The list to sort