This course website is from a previous semester. If you are currently in the class, please make sure you are viewing the latest course website instead of this old one.
Here is a general outline of the key concepts (arranged by topic) that you should know for Exam 02.
The exam will have the following format:
Python Scripting (multiple-choice, fill-in-the-blank)
Data Processing (multiple-choice)
Functional Programming (multiple-choice)
List Comprehensions (multiple-choice)
Generators (multiple-choice)
Concurrency and Parallelism (multiple-choice)
Translations: Convert Unix pipelines to Python code (coding on the computer)
All portions of the exam will take place online. Parts 1 through 6 will be an online quiz while Part 7 will require submitting code to your assignments repository.
This check list is meant to be representative, rather than exhaustive (ie. there may be questions that show up on the exam that are not shown below).
Exam 02 will take place during our normal lecture session on Wednesday, March 16 from 12:50 PM - 1:40 PM in 101 DeBartolo Hall.
As noted above, a portion of the exam with be a Google Form Quiz, while the remaining component with require coding and submitting work to your assignments GitHub repository.
Students will be permitted access to any material in their textbooks, notes, assignments, and the Internet.
Although students are allowed to use their computers and the Internet during the exam, students may not communicate with others or solicit answers from others. Students caught sharing solutions or violating any portion of the honor code will receive a zero on the exam.
How is Python different from the Bourne shell? How is it similar?
How do we manage control flow in Python? How do we utilize these constructs?
Conditionals
Loops
Exceptions
Functions
What data structures do we have in Python? What are their basic operations? When would we want to use each type of data structure?
Lists / Tuples
Dictionaries / Sets
How do we do the following in Python?
Process command-line arguments
Read standard input (line-by-line)
Read input from files
Access environment variables
Change the case of a string
Split a string, combine a list of strings
Slice a list
Execute an external command
Process JSON data from the web
Count with dictionaries
Sort lists and dictionaries
Write Python code snippets to perform the following tasks (don't worry about she-bangs or imports):
Print out each element of a list (one element per line).
Print the contents of stdin
(line-by-line).
Print the first 10 items of a list.
Print the length of a list.
Print the largest and smallest elements of a list.
Print the first and last words in the string "Let this promise in me start, Like an anthem in my heart".
Print the results of the ps aux
command.
Print the contents of a specific webpage.
Given the following data:
comics = {
"marvel": ["deadpool", "spider-man", "wolverine"],
"dc" : ["batman", "superman"]
}
For each of the following expressions, state the output value:
len(comics)
list(comics.keys())[0]
list(comics.values())[-1]
comics['marvel'][1]
comics['dc'][-1][-3:]
Given the following Unix pipelines, write Python code that accomplishes the same task.
Note: No credit will be given for simply calling os.system
on the
given pipeline. You may use os.popen
to read the output of one command,
but you may not use a pipeline.
cat /etc/passwd | cut -d : -f 1 | grep d$ | wc -l
cat /etc/passwd | cut -d : -f 3 | grep -E '^[0-9]{2}$' | sort | uniq
curl -sL http://yld.me/raw/lmz | cut -d , -f 1 | grep -Eo '^[^jfs].*'
curl -sL http://yld.me/raw/lmz | cut -d , -f 2 | grep -Eo '^B.*' | sort
who | sed -rn 's|.*\((.*)\).*|\1|p' | sort | uniq
ls -l /etc | awk '{print $2}' | sort | uniq -c
What is the difference between imperative and functional programming?
What are some benefits of functional programming?
How is functional programming related to the Unix Philosophy?
How do we use map, filter, and lambda to do functional programming in Python?
What is a generator and how it is different from a list?
What does the yield command do?
How do we convert a list comprehension to a generator expression?
Translate the following imperative code:
def find_squares(start, end):
squares = []
for number in range(start, end):
if math.sqrt(number) == int(math.sqrt(number)):
squares.append(number)
return squares
What is the difference between concurrency and parallelism?
What are some problems with concurrency?
How does functional programming help enable concurrency and avoid these problems?
What does it mean for a problem to be task parallel, data parallel, or embarrassingly parallel? Examples?
Identify whether the statements below are True or False and explain why.