Skip to content

Instantly share code, notes, and snippets.

@kalloc
Created January 22, 2012 00:49
Show Gist options
  • Save kalloc/1654827 to your computer and use it in GitHub Desktop.
Save kalloc/1654827 to your computer and use it in GitHub Desktop.
consonant = set(['q', 'w', 'r', 't', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'])
vowel = set(['e', 'y', 'u', 'i', 'o', 'a'])
def to_nouns(word):
if word[-1] in consonant and (word[-2:] in ['sh', 'ss', 'ch'] or word[-1] == 's'):
return word+'es'
elif word[-1] == 'y' and word[-2] in consonant:
return word[:-1]+'ies'
return word+'s'
TEST = ['stamp', 'key', 'camera', 'bus', 'class', 'wish', 'match', 'berry', \
'party', 'country', 'day', 'child', 'person', 'woman', 'man' ]
for word in TEST:
print 'from singular %s to plural %s' % (word, to_nouns(word))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment