PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# function to temporary install small modules in Sololearn
install = lambda package: __import__('os').system("pip3 install -qq --target='/usercode' " + package)
# install the inflect module
install('inflect')
import inflect
# initialize inflect as p
p = inflect.engine()
# test list of singular nouns
singular_words = ["apple","child","ox"]
print('singular form:', *singular_words)
# list comprehension to apply p.plural to items in singular_words
plural_words = [p.plural(s) for s in singular_words]
print('plural form: ', *plural_words)
# results of p.plural with count==1
for s in singular_words:
print(1, p.plural(s, 1))
# results of p plural with count>1
for i,s in enumerate(singular_words,2):
print(i, p.plural(s, i))
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run