Study Guides (390,000)
CA (150,000)
SFU (5,000)
CMPT (100)
Forgot (1)
Final

CMPT 383 Study Guide - Final Guide: Ironpython, Cpython, Type System


Department
Computing Science
Course Code
CMPT 383
Professor
Forgot
Study Guide
Final

This preview shows half of the first page. to view the full 3 pages of the document.
Final review questions, CMPT 383 Fall 2010
Python code
Consider the attached Python listing (on the last page). You are encouraged to run the examples to
understand how they work.
1. Function example1 executes function doSomething() on every element in list
container. Change the function to execute doSomething() on every element in
container, assuming container is a Python set instead of a list. How are the two
versions similar? How do they differ? What is the name for this property?
2. Consider function example2. What are the scopes of variables a, b, and c? Which values, if
any, will persist after the function returns?
3. Consider the sequence of code Example 3. What is printed by the two print statements? Why?
4. Consider the sequence of code Example 4. Assume that list a and tuple b have the
representations in memory I discussed in class.
Which variable should permit faster indexing (i.e., would a[750] or b[750] be faster
or would they both be the same speed)?
How expensive would the conversion from list form to tuple form be? Would you want
to do that in a tight loop?
What are the advantages of the internal representation for a list over the internal
representation for a tuple?
5. Consider the sequence of code Example 5. At the point of the statement b = a, how many
bindings exist for the name a?
6. Consider a (vastly simplified) mapping application that converts locations to business street
addresses and vice versa. Assume locations are represented by a (latitude, longitude) tuple,
with latitude and longitude each represented by a tuple of two numbers and an address is a
string, such as “8888 University Drive”.
Create a dictionary that converts 49.279, 122.920 to “8888 University Drive” and 0,0 to
“Santa's House”.
Write a for loop that prints every (location, address) pair in the dictionary
Write a routine that, given an address, returns its location in the above dictionary or
(None, None) if the address is not in the dictionary.
Python principles
1. Describe the difference between mutable and immutable types in Python. Give an expression
where only an immutable type can appear.
C# code and principles
Be able to do the kinds of questions asked on the midterm.
You're Reading a Preview

Unlock to view full version