CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger.

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 Feb 26, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science January 13, 2015 Prof. Rodger compsci 101 spring
Beyond Lists: Other Data Structures CS303E: Elements of Computers and Programming.
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
13-1 Sets, Bags, and Tables Exam 1 due Friday, March 16 Wellesley College CS230 Lecture 13 Thursday, March 15 Handout #23.
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.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 Dictionaries and Sets.
CompSci 101 Introduction to Computer Science November 18, 2014 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 TDAFB (after fall break) l Hear via about plans to catch-up and stay-ahead  Profs. Rodger and Astrachan to.
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 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 October 22 l Images, tuples, RGB color model  Image processing by understanding API  Image processing with tuples.
Sets Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
CompSci 101 Introduction to Computer Science January 28, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
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 February 11, 2016 Prof. Rodger.
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 March 24, 2016 Prof. Rodger compsci 101, spring
Python Sets and Dictionaries Peter Wad Sackett. 2DTU Systems Biology, Technical University of Denmark Set properties What is a set? A set is a mutable.
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.
Numbers and Sets. A set is a collection of objects. So, any collection of things, such as numbers, can be called a set. To show that we have a set, we.
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 Sept 13, 2016 Prof. Rodger compsci101 fall161.
Sets Set is an unordered list of items
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
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
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
CompSci 101 Introduction to Computer Science
Michael Ernst CSE 140 University of Washington
6. Dictionaries and sets Rocky K. C. Chang 18 October 2018
CompSci 101 Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Bananas apples peaches pears.
Ruth Anderson UW CSE 160 Spring 2018

CSE 231 Lab 9.
Introduction to PYTHON
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Ruth Anderson UW CSE 160 Winter 2016
Presentation transcript:

CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger

Announcements Reading and RQ due next time Assignment 5 out today APT 4 due today, APT 5 out Lab 6 this week –Read APT Anagramfree and Assignment 5 before going to lab! Today: –Focus on problem solving with sets, list comprehensions

Duke ACM ACM – Computer Science student club –Association of Computing Machinery Event tonight! 6pm Physics 128 Tech Entrepreneurship talk with Envested CEO and CTO bit.ly/dukeacmtechtalk Join the dukelist for dukeacm

Grace Hopper Celebration of Women in Computing Apply for fellowships to go to the conference, by march 30! –Pays your way to the conference 15,000 women in computing ghc.anitaborg.org

More on List Comprehensions bit.ly/101sp Problem: Given a list of strings, return the longest string. If there are more than one of that length, return the first such one. [‘kiwi’, ‘plum’, ‘orange’, ‘lemon’, ‘banana’] Write a list comprehension for this problem compsci101 spring2015

Exam 1 scores compsci101 spring20167 How do you generate this? Start with file of test scores

Process Exam Scores bit.ly/101sp Calculate –total number of scores –Average score –Median score Print a visualization of the grades Get snarf file

Python Sets Set – unordered collection of distinct items –Unordered – can look at them one at a time, but cannot count on any order –Distinct - one copy of each Operations on sets: –Modify: add, clear, remove –Create a new set: difference(-), intersection(&), union (|), symmetric_difference(^) –Boolean: issubset = Can convert list to set, set to list –Great to get rid of duplicates in a list

Summary (from wikibooks) set1 = set() # A new empty set set1.add("cat") # Add a single member set1.update(["dog", "mouse"]) # Add several members set1.remove("cat“) # Remove a member - error if not there print set1 for item in set1: # Iteration or “for each element” print item print "Item count:", len(set1) # Length, size, item count isempty = len(set1) == 0 # Test for emptiness set1 = set(["cat", "dog"]) # Initialize set from a list set3 = set1 & set2 # Intersection set4 = set1 | set2 # Union set5 = set1 - set3 # Set difference set6 = set1 ^ set2 # Symmetric difference (elements in either set but not both) issubset = set1 <= set2 # Subset test issuperset = set1 >= set2 # Superset test set7 = set1.copy() # A shallow copy (copies the set, not the elements) set8.clear() # Clear, empty, erase

Creating and changing a set

Set Operations

Set Examples bit.ly/101sp poloClub = set(['Mary', 'Laura', 'Dell']) rugbyClub = set(['Fred', 'Sue', 'Mary']) Questions: print [w for w in poloClub.intersection(rugbyClub)] print poloClub.intersection(rugbyClub) print [w for w in poloClub.union(rugbyClub)] print poloClub.union(rugbyClub)

Set Examples (cont) lista = ['apple', 'pear', 'fig', 'orange', 'strawberry'] listb = ['pear', 'lemon', 'grapefruit', 'orange'] listc = [x for x in lista if x in listb] listd = list(set(lista)|set(listb))

Assignment 5 - Hangman Guess a word given the number of letters. –Guess a letter –see if it is in the word and where. Demo Will start in lab

APT AnagramFree words = ["creation","sentence","reaction","sneak","star","rats","snake"] Returns: 4 “star” “rats”  both have letters: a r t s “snake” “sneak” “creation” “reaction” “sentence”

Problem Given two books: –How many words in each book? –How many unique words in each book? –What words that start with “r” are in one book and not the other book?