Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Python | Schedule | Submit

Saint Louis University

Computer Science 150
Introduction to Object-Oriented Programming

Michael Goldwasser

Spring 2013

Dept. of Math & Computer Science

Additional Practice

Loops and Conditionals

In order to practice use of loops and conditionals, we wanted to play with an easily accessible data set. Our solution is to use a system-wide list of words and phrases that supports spell-checking and other language tools (here is a copy). We load those words into a Python list with the following command:

words = [line.strip() for line in open('/usr/share/dict/words') if line.strip()]

Develop Python code to determine the following (consider each problem independently). As an aide on using the str class, feel free to refer to online documentation.

  1. Create a list of all words, converted to lowercase.

  2. Create a list of all words that were originally lowercase.

  3. Create a list of all words that have an apostrophe character.
    (on turing, there are 26226 such words)

  4. Find all entries with 5 or more lowercase 's' characters.
    (on turing there are 166 such words)

  5. Compute the average number of characters per entry, and the average number of vowels ('aeiou') per entry.
    (on turing, avg word length is 8.467 and average number of vowels is 2.978)

  6. Classic spelling rule is "i before e except after c"; create a list with exceptions to the typical rule.
    (on turing there are 784 such words)

  7. Find words that, after being lowercased, have consecutive repeated characters (e.g., filled which has ll). Be careful that each original word appears at most once in the result (e.g., coffee, that has both ff and ee).
    (on turing there are 18447 such words)

  8. Find words that have an 'a' followed (not necessarily consecutively) by a 'b' and then by a 'c', such as with tablecloth.
    (on turing there are 249 such words)

  9. Generalize the previous problem, allowing the user to select a given pattern (e.g., pattern='abcde'), and determine those words in which the pattern occurs as a (not necessarily consecutive) subsequence.
    (on turing there is a single word that has 'abcde' as a subsequence; can you find it?)

  10. Make up your own challenge...

(our solutions)
Michael Goldwasser
CSCI 150, Spring 2013
Last modified: Tuesday, 12 February 2013
Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Python | Schedule | Submit