Compsci 06/101, Spring 2011, Lab 10

By entering your name/net-id below you indicate you are present for Lab 10 to answer these questions and that you were part of the process that resulted in answers being turned in.

Name: ______________    Net id: _____________ || Name: ______________    Net id: _____________

Name: ______________    Net id: _____________ || Name: ______________    Net id: _____________

Regex Questions

  1. How many five letter words are there that end with the letter 'd'?
    
    
    
    
    
    
    
    
    
  2. The regular expression [aeiou]$ indicates there are 6988 words that end in a vowel. How many words are there that start and end with a vowel?
    
    
    
    
    
    
    
    
  3. How many words are there that start and end with the same vowel --- words like amoeba?
    
    
    
    
    
    
    
    
    
    
  4. The words obsequious and pharmacopoeia each contain four vowels in a row. How many words are there that contain four consecutive vowels?
      
    
    
    
    
    
    
    
    
    
  5. The word maintaining contains the two letter sequence "in" repeated three times --- in genomics this could be called a triple-repeat. How many words are there that contain the two letter sequence "in" repeated three times (letters can appear between the "in" repeats)?
    
    
    
    
    
    
    
    
    
    
    
  6. The word contentment contains the two letter sequence "nt" repeated three times. How many words contain some two letter sequence repeated three times? For example, both contentment and maintaining are among such words.
      
    
    
    
    
    
    
    
    
    
    
    
  7. The word interpreter contains the two letter sequence "er" followed by the sequence reversed "re" followed by the original two letter sequence "er". How many words are there with some two letter sequence followed by the sequence reversed followed by the original sequence (letters between the repeats are ok)?
    
    
    
    
    
    
    
    
    
    
    
  8. You may have seen the word puzzle "what English word contains three doubled-letters in a row?" to which the answer is "bookkeeper" with double-o, double-k, double-e in a row. If we allow letters to appear between the doubled-letters we get more words, like unsuccessfully which has a double-c, double-s, and double-l. How many such words are there with three doubled letters appearing anywhere in the word, not necessarily adjacent to each other?
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  9. The regular expression ((.).\2).*\1 matches the 12 words below (and only these words). Explain why these words match, how the regular expression works. Note that the expression (.) is the second tagged expression since the first left parenthesis begins the first tagged expression -- you count tagged expressions by the order in which the left-parenthesis appears in reading left-to-right.

    amalgamate
    amalgamated
    amalgamates
    amalgamatating
    amalgamatation
    assesses
    dereference
    monotonous
    monotonously
    monotonousness
    possesses
    sensitivities
    

  10. The regular expression ((.).\2){3} matches the two words below (and only these two words). Explain why these words match, i.e., how the regular expression works.
    agamemnon
    precipitateness
    
    
    
    
    
  11. Write a word-puzzle question you want the rest of the lab/class to answer, and then answer it. We'll pose these questions to the class as the last part of this recitation, then we'll answer each group's questions.
    
    
    
    
    
    
    
    
    
    
    
    
    

List Comprehension Questions

Assume that letters is a list of strings and that table is a dictionary of strings (as keys) to lists of strings (as values). For example:


letters = ["snap", "crackle", "pop", "broom", "knee"]

table = {"fruit":["apple", "cherry", "guava"],
         "candy":["snickers", "milky way", "jujube"]
        }

Recall that table.keys() is a list of the keys in table and that table.values() is a list of the values in table. In the example above the latter is a list in which each element is a list of strings>
  1. The list of strings in letters that are more than five letters long.
    
    
    
    
    
    
  2. The list of strings in letters that contain two occurrences of the letter 'f'.
    
    
    
    
    
    
  3. A list of strings in letters in which there are no duplicates, i.e., if a string occurs more than once in letters it should occur just once in the list that results from the list comprehension you write.
    
    
    
    
    
    
    
  4. The keys in table whose corresponding value contains more than four strings.
    
    
    
    
    
    
  5. The keys in table whose corresponding value contains no duplicates.