By
Vasudev Ram
Like anyone else, every now and then I hear people use
redundant words words or phrases. Hey, I do it myself sometimes, but am trying to do less of it.
So one day recently, thinking about ways to help with this issue, I came up with the idea for this program, called "
Cut the crap!".
You
feed it a redundant word or phrase, and if it "
knows" it, it spits out the
concise (unredundant? dundant? :-) version. Think a
Strunk-and-White-like Python bot.
So, here's the Python code for
cut_the_crap.py, an
absolutely essential tool for writers. The phrases and words are hardcoded as of now, in this first version, but you can easily modify the program to read them from any persistent store (such as a file or database), along with the concise substitutes:
# cut_the_crap.py
# Author: Vasudev Ram
# Purpose: Given a redundant word or phrase, emits a concise synonym.
# See Strunk and White, et al.
from string import lower
from random import randint
d = {
'at this point in time':
['now', 'at present', 'at the moment', 'at this moment',
'currently', 'now', 'presently', 'right now'],
'absolutely complete': ['complete'],
'absolutely essential': ['essential', 'indispensable'],
'actual experience': ['past experience', 'experience'],
'as to whether': ['whether'],
'try out': ['try']
}
def cut_the_crap(word):
if word in d:
words = d[word]
i = randint(0, len(words) - 1)
return words[i]
else:
return ""
def get_the_word():
crap_word = raw_input("Enter your word (or type 'exit'): ")
return crap_word
def main():
word = get_the_word()
while lower(word) != 'exit':
right_word = cut_the_crap(word)
if right_word != "":
print "Cut the crap! Say:", right_word
print
word = get_the_word()
print "Bye."
if __name__ == '__main__':
main()
And here is a sample run, entering a few redundant words and phrases:
$ py cut_the_crap.py
Enter your word (or type 'exit'): at this point in time
Cut the crap! Say: at the moment
Enter your word (or type 'exit'): at this point in time
Cut the crap! Say: right now
Enter your word (or type 'exit'): at this point in time
Cut the crap! Say: now
Enter your word (or type 'exit'): as to whether
Cut the crap! Say: whether
Enter your word (or type 'exit'): absolutely essential
Cut the crap! Say: indispensable
Enter your word (or type 'exit'): absolutely essential
Cut the crap! Say: essential
Enter your word (or type 'exit'): try out
Cut the crap! Say: try
Enter your word (or type 'exit'): exit
Bye.
- Enjoy.
- Vasudev Ram - Online Python training and programming
Dancing Bison Enterprises
Signup to hear about new products or services that I create.
Posts about Python Posts about xtopdf
Contact Page