Skip to content

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

License

Notifications You must be signed in to change notification settings

JustinBacher/pluralize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages