Created
December 10, 2018 18:24
-
-
Save MLKrisJohnson/a38ddb391c9cbb064072ba15a506e6cb to your computer and use it in GitHub Desktop.
Return the singular or plural form of text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pluralize(count, arg1=None, arg2=None): | |
"""Return pluralized string. | |
If the count is 1, then if two additional arguments are provided, return the | |
first one. Otherwise, return an empty string. | |
if the count is not 1, then if two additional arguments are provided, return | |
the second one. If one additional argument is provided, return it. | |
Otherwise return "s". | |
Example usages: | |
'%d cat%s.' % (count, pluralize(count)) | |
'%d walrus%s' % (count, pluralize(count, 'es')) | |
'%d cherr%s' % (count, pluralize(count, 'y', 'ies')) | |
""" | |
if count == 1: | |
if arg2 is not None: | |
return arg1 | |
else: | |
return "" | |
else: | |
if arg2 is not None: | |
return arg2 | |
elif arg1 is not None: | |
return arg1 | |
else: | |
return "s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment