Sample solution for Assignment 2
Click here to get the file
Size
1 kB
-
File type
text/python-source
File contents
import string
def removeJunk(mystring):
newstring = ''
for char in mystring:
if char in string.letters or char == ' ':
newstring += char
return newstring
def stringToWords(mystring):
return mystring.split()
def removeUnwantedWords(mylist):
unwanted = ['of', 'at', 'the', 'and']
new_list = []
for word in mylist:
if word not in unwanted:
new_list = new_list + [word]
return new_list
def generateAcronym(mystring):
if type(mystring) != str:
return None
filtered = removeJunk(mystring.lower())
wordlist = stringToWords(filtered)
wordlist = removeUnwantedWords(wordlist)
if (len(wordlist) == 0):
return None
acronym = ''
for word in wordlist:
acronym += word[0].upper()
return acronym
by
Max Chang
—
last modified
2007-02-01 09:36 AM