Course Home | Class Schedule | Assignments | Git Submission | Perusall | Python | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2018

Computer Science Department

Homework Assignment 09

Comprehension Syntax

Overview

Topic: Comprehension syntax
Related Reading: Ch. 09
Due: 10:00am, Tuesday 2 October 2018

Please make sure you adhere to the policies on academic integrity.


Problems to be Submitted (20 points)

  1. (6 points)

    Assume that tokens is a list of strings read from a text file, that represent numeric values (e.g., ['23', '35', '8', '200']).

    Give a single line that uses comprehension syntax to produce a new list, named vals, which are the corresponding integer values (e.g., [23, 35, 8, 200]).

  2. (6 points)

    Assume that nouns is a list of strings. Given a line that produces a new list, plural, containing all of the original words that end with the character 's'. (Yes, I realize that these might not actually represent plurals, but this is just an exercise.)

  3. (8 points)

    On our recent exam there was a question that involved converting a phrase such as 'laughing out loud' to an acronym such as 'LOL'. (Actually, the question was to use a loop to do this converstion for many different phrases, but we will focus on a single phrase for this question.)

    We could accomplish the goal using traditional techniques as in the following:

    initials = []
    for word in phrase.split():
        initials.append(word[0].upper())
    acronym = ''.join(initials)
    

    Your task is to give a single line of code of the form

    acronym = ???
    that accomplishes the above task.


Michael Goldwasser
CSCI 1300/5001, Fall 2018
Last modified: Wednesday, 03 October 2018
Course Home | Class Schedule | Assignments | Git Submission | Perusall | Python | Tutoring