Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- #
- import sys
- USAGE = """
- Usage: python %s [OPTION] FILE
- prints the wattitude for each line in the given FILE.
- --help, -h show this
- --intro, -i the reasoning behind this madness
- --moo super powers
- """
- INTRO = """Wattitude Calculator
- A word's wattitude is derived as:
- 1. let a = 1, ..., z = 26
- 2. sum the value of each letter
- 3. ???
- 4. profit!
- This spawned from the "attitude = 100%" meme, it uses an blatantly
- ridiculous scale of measure. So I said to myself, "hey, what other
- words have keen numbers?", replied me, "could be some nice coicidences
- other Wesley. I bet it's easy to write in Python!".
- Words live at http://wordlist.sourceforge.net
- enjoy~wezATdarknet.co.za
- """
- def word_attitude(word):
- """Calculates and returns the wattitude of the given word. \
- This method is not optimized like file_attitude() is, and is \
- here for academic reasons only."""
- return sum([ord(e) - ord('a') + 1 for e in word.lower()])
- def file_attitude(filename):
- """Calculates the attitude of a file, one word per line.
- """
- # use a lookup for alpha values. since we need a = 1 via a
- # zero based list, include #64 as the first character.
- alpha_lookup = [chr(i).lower() for i in range(64, 65 + 26)]
- # read the file into memory. this is significanly faster than
- # line-by-line.
- try:
- f = open(filename, 'r')
- words = f.readlines()
- f.close()
- except IOError as e:
- print(e)
- return
- # init
- avg = []
- # mathematically procure the attitudes
- for word in words:
- attitude = sum([alpha_lookup.index(e) for e in word.lower() if e in alpha_lookup ])
- avg.append(attitude)
- print('%d = %s' % (attitude, word[:-1]) )
- # averages
- for j in range(1, 200):
- a = avg.count(j)
- if a > 0:
- print('%d x %d times > %s%s' % (j, a, ' ' * 10, '#' * a))
- def parse_args():
- """ process command line arguments and act out accordingly (or not).
- """
- if len(sys.argv) == 1:
- print('You might want to try adding --help...')
- return
- args = sys.argv[1:]
- for arg in args:
- if arg in ('--intro', '-i'):
- args.remove(arg)
- print(INTRO)
- if arg in ('--help', '-h'):
- args.remove(arg)
- print(USAGE % (sys.argv[0]))
- if arg == '--moo':
- args.remove(arg)
- print("""
- (__)
- (oo)
- /------\/
- / | ||
- * /\---/\
- ~~ ~~
- ...."Have you mooed today?"...
- """)
- print('the wattitude of "moo" is %d' % (word_attitude('moo')))
- print('(nearly the answer to life, the universe and everything!)')
- if len(args) > 0:
- file_attitude(args[-1])
- if __name__ == "__main__":
- parse_args()
- #I played around with Python and words, and wattitude.py is the result.
- #Usage: python %s [OPTION] FILE
- #prints the wattitude for each line in the given FILE.
- #A word's wattitude is derived as:
- #1. let a = 1, ..., z = 26
- #2. sum the value of each letter
- #3. ???
- #4. profit!
- #I ran this on the jargon file word list (link in the source).
- #Did I find interesting wattitudes?
- ## 101 = hackitudes
- ## 100 = freewares
- ## 100 = wizards
- ## 42 = Borg
- ## 42 = amoebae
- ## 42 = hacks
- #amoebae is a perfect match. profit!
- #The largest wattitude:
- ## 195 = monstrosities
- #The smallest wattitude:
- ## 25 = boga
- #Frequency counts [1] shows us that Wattitude is prevalent between the 37 and 104 range, forming a
- #[1]: python wattitude.py jargon-wl/word.lst | sort -V | grep times
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement