Inflect

7.5.0 · active · verified Sun Mar 29

Inflect.py is a Python library designed to correctly generate plurals, singular nouns, ordinals, indefinite articles (a/an), and word-based representations of numbers. Its functionality is primarily focused on the English language. As of version 7.5.0, it maintains an active development and release cadence, with regular updates addressing features, bug fixes, and compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates common `inflect` functionalities: pluralizing nouns conditionally, generating ordinal numbers, converting numerals to words, and selecting indefinite articles ('a' or 'an').

import inflect

p = inflect.engine()

# Pluralization
word = 'cat'
count = 5
print(f"The plural of '{word}' is '{p.plural(word)}'")
print(f"I saw {count} {p.plural_noun(word, count)}.")

# Ordinal numbers
number = 21
print(f"The ordinal of {number} is {p.ordinal(number)}")

# Numbers to words
big_number = 1234567
print(f"'{big_number}' in words is '{p.number_to_words(big_number)}'")

# Indefinite articles
print(f"An apple and {p.an('historical object')}")

view raw JSON →