Compsci 101, Fall 2014, Classwork Nov 4, 2014
Solve these problems and enter them in the google forms for today.
Answers to problems 1 and 2
in www.bit.ly/101fall14-1104-01
Problem 1:
What is the resulting output? Think, don't cut and paste!
d = {'duke':30, 'unc':50, 'ncsu':40}
print "d.values()", d.values()
print "d.keys()", d.keys()
d['duke'] = 80
d.update({'ecu':40, 'uncc':70})
print "d.values()", d.values()
Problem 2:
Assume d is the resulting dictionary from above.
What is the difference between these 3?
print "d.items()", d.items()
print "d.iteritems()", d.iteritems()
print "d", d
Answers to problems 3 and 4
in www.bit.ly/101fall14-1104-02
Problem 3:
Using the dictionary from above, write Python code to determine how many schools have more than 40 attendees?
Problem 4:
Using the dictionary from above, which schools have more than 40 attendees?
Answer to problem 5
in www.bit.ly/101fall14-1104-03
Problem 5:
Part A: Create a new dictionary from d that can easily answer questions such as, which
schools have X attendees.
Part B: Create a new dictionary from d mapping groups of 50 attendees,
group 0-49 together, 50-99, etc.
Answer to problem 6
in www.bit.ly/101fall14-1104-04
Problem 6:
Create a dictionary of popular song titles and how many times each song
is 1st place, 2cd place, 3rd place... see songtitles.py
Answer to problem 7
in www.bit.ly/101fall14-1104-05
Problem 7:
Discuss with others an algorithm for solving the APT EmailsCourse.
Write in words (not code) your algorithm.