def pluralize(word, **kwargs):
    count = kwargs.get('count', None)
    plural_suffix = kwargs.get('plural_suffix', 's')
    singular_suffix = kwargs.get('singular_suffix', None)

    if count is not None:
        word = [count, word]
    elif not isinstance(word, list):
        word = word.split(' ')
        if int(word[0]) != 1:
            word[1] += plural_suffix
        elif singular_suffix:
            word[1] += singular_suffix
    except ValueError:  # Invalid string that's not a number.
    if count is not None:
        return word.pop()
    return ' '.join(word)
Sample Usage:
total_comments = 50  # from db change to 1 or more
# for words that you can just add s
print pluralize('comment', count=total_comments)

Can be used as a filter for jinja templates. Easily makes a word plural base on inputs. Useful for comment count(s).

Pythoneer 6 years ago