mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
Added a docstring and doctested nItems.
This commit is contained in:
parent
18a8725905
commit
325e751149
15
src/utils.py
15
src/utils.py
@ -287,6 +287,17 @@ def pluralize(i, s):
|
||||
return s + 's'
|
||||
|
||||
def nItems(n, item, between=None):
|
||||
"""Works like this:
|
||||
|
||||
>>> nItems(1, 'clock')
|
||||
'1 clock'
|
||||
|
||||
>>> nItems(10, 'clock')
|
||||
'10 clocks'
|
||||
|
||||
>>> nItems(10, 'clock', between='grandfather')
|
||||
'10 grandfather clocks'
|
||||
"""
|
||||
if between is None:
|
||||
return '%s %s' % (n, pluralize(n, item))
|
||||
else:
|
||||
@ -386,4 +397,8 @@ class IterableMap(object):
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys, doctest
|
||||
doctest.testmod(sys.modules['__main__'])
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user