Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

pluralize

This is my simple solution to the common issue of formatting numbers into sentences such that making them plural is a nessecity. While you could easily use an if statement, this allows for much more use cases. It all started with this question on stackoverflow.

Currently this is only for python 3.6+ as it uses f-strings

Output a simple number (deleted) to user readable format

deleted = 2

Desired output

"2 entries were removed"

The old way of getting this output

print(f'Done! {deleted} entr{"y was" if deleted == 1 else "ies were"} removed.')

or

print(f"{deleted} {(plural, singular)[abs(num) == 1]}")

With pluralize

import pluralize

deleted = pluralize(deleted, singular="entry", plural="entries")
print(f"{deleted} were removed")

About

A very simple and adhoc approach to outputting numbers into human readable form

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages