CompSci 101 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
Advertisements

CompSci 101 Introduction to Computer Science January 13, 2015 Prof. Rodger compsci 101 spring
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
CompSci 6 Introduction to Computer Science October 20, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
CompSci 101 Introduction to Computer Science Sept. 9, 2014 Prof. Rodger President Brodhead speech graduation 2010 CompSci 101 Fall
CompSci 6 Introduction to Computer Science November 1, 2011 Prof. Rodger.
CompSci 6 Introduction to Computer Science Sept 29, 2011 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not.
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151.
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
Compsci 101.2, Fall Plan for FWON l Review current assignments and APTs  Review Dictionaries and how to use them  Code and APT walk-through.
14. DICTIONARIES AND SETS Rocky K. C. Chang 17 November 2014 (Based on from Charles Dierbach, Introduction to Computer Science Using Python and Punch and.
CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
Compsci 101.2, Fall Plan for October 29 l Review dictionaries and their use  Very efficient, easy to use  Efficiency doesn't matter much for.
CompSci 101 Introduction to Computer Science February 10, 2015 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
Compsci 101.2, Fall Plan for eleven-four l Thinking about APTs and test problems  How do you choose: list, string, set, dictionary  Experience?
Compsci 101.2, Fall Plan for October l Structuring Data and Code for Efficiency  Computer time, how expensive is it?  Data storage, how.
CompSci 101 Introduction to Computer Science Feb 24, 2015 Prof. Rodger.
CompSci 6 Introduction to Computer Science Sept. 20, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
CompSci 101 Introduction to Computer Science March 17, 2015 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science February 25, 2016 Prof. Rodger compsci101 spring20161.
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science April 7, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 24, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger Lecture today by Sriram Vepuri.
CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science March 29, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CompSci 101 Introduction to Computer Science March 31, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science Sept 13, 2016 Prof. Rodger compsci101 fall161.
CompSci 101 Introduction to Computer Science
Compsci 201, Compare+Analysis
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 6 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
When to use Tuples instead of Lists
CompSci 101 Introduction to Computer Science
Compsci 201, Analysis+Markov
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Computer Science
CISC101 Reminders Slides have changed from those posted last night…
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
CompSci 101 Introduction to Computer Science
Introduction to Dictionaries
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CISC101 Reminders Assignment 2 due today.
Compsci 201, Collections, Hashing, Objects
CompSci 101 Introduction to Computer Science
Presentation transcript:

CompSci 101 Introduction to Computer Science March 28, 2017 Prof. Rodger compsci 101 spring 2017

Announcements No RQs until after Exam 2 Assignment 6 due Thursday APT Quiz 2 Sun-Tue APT 7 due today, APT 8 out Exam 2 is April 11 Lab this week! Today: More practice with Dictionaries, finish last time compsci 101 spring 2017

Lab this week - .csv files Answering questions about songs and movies compsci 101 spring 2017

Lab - .csv file compsci 101 spring 2017

Python shortcut you can ignore The zip function, tuples from two lists Does something right if lists have different sizes. Look it up words = ['dog', 'cat', 'fish', 'guava'] counts = [3, 2, 1, 5] cc = zip(word,counts) [('dog', 3), ('cat', 2), ('fish', 1), ('guava', 5)] You could easily write zip.... In one line with List comprehension to create tuples min or max? min Range - need index number for both lists yy = [(a[i], b[i]) for i in range(min(len(a),len(b)))] compsci 101 spring 2017

Python functions you CANNOT ignore We know how to sort, we call sorted Example: sorting tuples Function sorted returns a new list, original not changed What if sort by numbers instead of words? xx = [('dog', 3), ('cat', 2), ('fish', 1), ('guava', 2)] yy = sorted(xx) [('cat', 2), ('dog', 3), ('fish', 1), ('guava', 2)] What if we want to sort by numbers instead of words?

Use what you know You can re-organize data to sort it as you'd like, list comprehensions are your friend xx = [('dog', 3), ('cat', 2), ('fish', 1), ('guava', 2)] ... nlist = [(t[1],t[0]) for t in xx] [(3, 'dog'), (2, 'cat'), (1, 'fish'), (2, 'guava')] yy = sorted(nlist) [(1, 'fish'), (2, 'cat'), (2, 'guava'), (3, 'dog')] Notice that (2,'cat') comes before (2,'guava') Use what you know

APT – SortedFreqs bit.ly/101s17-0328-1 The returned frequencies represent an alphabetic/lexicographic ordering of the unique words, so the first frequency is how many times the alphabetically first word occurs and the last frequency is the number of times the alphabetically last word occurs compsci 101 spring 2017

Ways to count? bit.ly/101s17-0328-2 Dictionaries are faster than using lists? How fast is list.count(x) for each x? How long does list.count(x) if you do this for each x? How long does it take to compute a dictionary of counts compsci 101 spring 2017

Shafi Goldwasser 2012 Turing Award Winner RCS professor of computer science at MIT Twice Godel Prize winner Grace Murray Hopper Award National Academy Co-inventor of zero-knowledge proof protocols How do you convince someone that you know [a secret] without revealing the knowledge? Honesty and Privacy Work on what you like, what feels right, I know of no other way to end up doing creative work

APT Customer Statistics bit.ly/101s17-0328-3 compsci 101 spring 2017

Review Dictionaries Map keys to values Get all Counting: count how many times a key appears Key to number Store associated values Key to list or set Get all Keys, values or (key,value) pairs What question do you want to answer? How to organize data to answer the question compsci 101 spring 2017

Dictionary problems Number of students in ACM clubs bit Dictionary problems Number of students in ACM clubs bit.ly/101s17-0328-4 d = {'duke':30, 'unc':50, 'ncsu':40} d['duke'] = 80 d.update({'ecu':40, 'uncc':70}) print d.values() compsci 101 spring 2017

Dictionary problems – part 2 bit.ly/101s17-0328-5 Consider the Python dictionary below on schools that map schools to number of students d = {'duke':30, 'unc':50, 'ncsu':40, 'wfu':50, 'ecu': 80, 'meridith':30, 'clemson':80, 'gatech':50, 'uva':120, 'vtech':110} compsci 101 spring 2017