Everything you need to know to complete today's activities is covered in appendix A of our textbook. There are also several relevant sections from the official Python tutorial:
You may also want to take a look at the complete list of string methods.
removeVowels(string)
. This function
should take a string as an argument, and return a copy of that
string with all of the vowels (a, e, i, o and u) removed.
greeting = "" greeting = greeting + "H" greeting = greeting + "i"
main
function to your program, and use it to
test removeVowels
.
removeShortWords(string,
minLength)
. This function should take a string and a
length as arguments, and should return a new string in which all of the
words shorter than the specified length have been removed. For
example,
removeShortWords("I am happy to meet you", 4)should return the string
"happy meet"
. (Don't worry
about handling punctuation correctly. Punctuation marks may be
considered part of the word that they follow.)
split
method that splits
the string into a list of words. For example, after the following code segment:
greeting = "hello there" words = greeting.split()
words
will contain the list ['hello', 'there']
.
main
. I
suggest testing this function in conjunction
with removeVowels
as follows:
noShort = removeShortWords("I am happy to meet you", 4) noVowels = removeVowels(noShort) print(noVowels)The result should be
"hppy mt"
.
reverseString(string)
. This function
should take a string as an argument, and return a new string in
which the order of the individual characters has been reversed.
range
function or by using negative string indexing.
removeInfrequent(string,
minCount)
. This function should take a string as
an argument, and should return a new string in which all
words that occur fewer than minCount
times
have been removed.
For example,
removeInfrequent("This is great really really really great", 2)should return the string
"great really really really great "
.
dict
to
create a count for all the words. The second time
through, you can build the new string from all of the
words that have enough occurrences.
There is nothing to hand in for this assignment. Make sure that you save a copy of your code, either on a thumb drive, the N: drive, or by e-mailing it to yourself. If you worked with a partner, make sure both of you get a copy.