CompSci 101 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
Session 3BBK P1 ModuleApril 2010 : [#] Regular Expressions.
Advertisements

BBK P1 Module2010/11 : [‹#›] Regular Expressions.
CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
A Level Computing#BristolMet Session Objectives#U2 S8 MUST identify the difference between a procedure and a function SHOULD explain the need for parameters.
More on Regular Expressions Regular Expressions More character classes \s matches any whitespace character (space, tab, newline etc) \w matches.
Binary Search Trees continued Trees Draw the BST Insert the elements in this order 50, 70, 30, 37, 43, 81, 12, 72, 99 2.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Pattern matching with regular expressions A common file processing requirement is to match strings within the file to a standard form, e.g. address.
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
Introduction to Computing Using Python Regular expressions Suppose we need to find all addresses in a web page How do we recognize addresses?
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Perl and Regular Expressions Regular Expressions are available as part of the programming languages Java, JScript, Visual Basic and VBScript, JavaScript,
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
Computing Science 1P Large Group Tutorial: Lab Exam & Class Test Simon Gay Department of Computing Science University of Glasgow 2006/07.
May 2008CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science November 18, 2014 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.
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 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 6 Introduction to Computer Science Sept. 20, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
May 2006CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
CompSci 101 Introduction to Computer Science April 7, 2015 Prof. Rodger.
Compsci 101.2, Fall Plan for LWoC l Power of Regular Expressions  From theoretical computer science to scraping webpages  Using documentation,
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.2, Fall Plan for ThBThB l Programming and understanding …  Hierarchical structures and concepts What is a file system on a computer?
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 4 Java 1 Apr 2, 2009 Prof. Susan Rodger. Announcements Assignment 7 questions? –Beware having two events that kick in at the same time! –Beware.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
Regular Expressions Upsorn Praphamontripong CS 1110
CompSci 101 Introduction to Computer Science
Strings and Serialization
CompSci 101 Introduction to Computer Science
MSc/ICY Software Workshop , Semester 2
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Lecture 19 Strings and Regular Expressions
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CMSC201 Computer Science I for Majors Lecture 18 – Recursion
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
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
CS 1111 Introduction to Programming Fall 2018
Data Manipulation & Regex
CompSci 101 Introduction to Computer Science
CSE 303 Concepts and Tools for Software Development
And now for something completely different . . .
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Presentation transcript:

CompSci 101 Introduction to Computer Science ABP BlueEx McDon Loop Panda Nasher Sam 3 5 -3 Chris 1 Nat -1 April 18, 2017 Prof. Rodger compsci 101 spring 2017

Announcements No more RQ! Assign 8 due Thurs., Assign9 due Apr. 26 APT 10 due Tues, Apr 25 Lab this week Exam 2 back Today: Review Recursion Regular Expressions Assignment 8 Recommender

Assignment 9 Due Apr 26 Shhh! No late penalty til Apr 28! Write a song, make a video about your experience with CompSci 101 compsci 101 spring 2017

Assignment 8 From User Rating to Recommendations Spectre Martian Southpaw Everest PitchPerfect 2 3 -3 5 -2 2 4 1 -1 What should I choose to see? What does this depend on? Who is most like me? How do we figure this out compsci 101 spring 2017

ReadAllFood modules: Food Format All Reader modules return a tuple of strings: itemlist and dictratings dictionary Translated to: Give the example formatted, BUT NOTE THE RIGHT END IS CUT OFF

Follow 12-step process ReadFood first! Read input and save it Get list of restaurants – use that ordering! Set? For each person For each restaurant and its rating Must find location of restaurant in itemlist Then update appropriate counter Print any structure you create to check it compsci 101 spring 2017

Recursion Review Function calls a clone of itself Smaller problem Must be a way out of recursion Solving a smaller version of the original problem, must be smaller in some way. Must also get smaller and smaller and then must be a way where it is so small you can just solve the problem. compsci 101 spring 2017

Example Mystery(5) is 1 + Mystery(2) = 1 + 4 = 5 = 1 + 3 = 4 = 1 + 2 = 3 compsci 101 spring 2017

Review: Recursion to find ALL files in a folder A folder can have sub folders and files A file cannot have sub files def visit(dirname): for inner in dirname: if isdir(inner): visit(inner) else: print name(inner), size(inner) Is that a directory? If not a directory, it will be a file Calls an instance that is smaller compsci 101 spring 2017

Something Recursion bitly/101s17-0418-1 compsci101 spring17

Revisit the APT Bagels Recursively compsci 101 spring 2017

APT Bagels Recursively bit.ly/101s17-0418-2 D) compsci 101 spring 2017

Recursion in Pictures http://xkcd.com/543/ compsci 101 spring 2017

More: Recursion in Pictures http://xkcd.com/688/ compsci 101 spring 2017

What is Computer Science? … "it is the study of automating algorithmic processes that scale." https://en.wikipedia.org/wiki/Computer_science If you need to find one email address on a webpage, you don't need computer science If you need to scrape every email address, that number in the 10's to 100's, you could use help compsci 101 spring 2017

How do you solve a problem like … How many words end in "aria"? Start with "aria"? Contain "aria"? Why would you care about this? Can you find ola@cs.duke.edu, susan.rodger@duke.edu, and andrew.douglas.hilton@gmail.com when searching through a webpage source? What is the format of a "real" email address? How do you solve a problem like "Maria" is from sound of music compsci 101 spring 2017

Examples of regex's at work What do aria$ and ^aria and aria share? Answers to previous question What about the regex .+@.+ Turns out that . has special meaning in regex, so does +, so do many characters We'll use a module RegexDemo.py to check Uses the re Python library Details won't be tested, regex knowledge will compsci 101 spring 2017

Regex expressions Regex parts combined in powerful ways Each part of a regex "matches" text, can extract matches using programs and regex library ^ is start of word/line, $ is end Expressions that match single characters: A, a, 9 or … Any character matches itself . Matches any character \w Matches alphanumeric and _ \d Matches digit \s Matches whitespace compsci 101 spring 2017

Regex expressions Repeat and combine regex parts * means 0 or more occurrences/repeats + means 1 or more occurrences/repeats ? Means (after * or +) to be non-greedy Expressions match more than one character [a-zAB] Brackets create character class (regex) Tag or group a regex \1 or \2 Matches previously grouped regex {1} or {n} Repeat regex 1 or n times compsci 101 spring 2017

Regex examples tried and explained Five letter words ending in p? Starts 'd'? ^\w\w\w\wp$ but not ....p$ Seven letter words, or seven ending with 'z' Difference between ^\w{7}$ and ^\w{7} Words that start with a consonant: ^[^aeiou] double meaning of ^ compsci 101 spring 2017

Regex examples tried and explained Five letter words ending in p? Starts 'd'? ^\w\w\w\wp$ but not ....p$ Seven letter words, or seven ending with 'z' Difference between ^\w{7}$ and ^\w{7} Start and end with the same two letters like sense and metronome, decipher this: ^(\w\w).*\1$ Start and end with three letters reversed, like despised and foolproof? compsci 101 spring 2017

Summary of Regular Expressions regex purpose . any character * zero or more of previous regex \w any alphanumeric character (and _) + one or more of previous regex \s any whitespace character *? or +? non-greedy version of either * or + \d any digit character () tag/group a regular expression [] character class, e.g., [A-Z] or [aeiou] \1, \2, .. match numbered tagged/grouped regex {n} n occurrences of preceding regex ^ beginning of line/string [^...] not the characters in the class, e.g., [^aeiou] $ end of line/string compsci 101 spring 2017

Regex Questions bit.ly/101s17-0418-3 compsci 101 spring 2017

Answer Questions bit.ly/101s17-0418-4 SortByFreqs APT Sort items by their frequency, then sorted in frequencies. compsci101 spring 2017

Take Exam questions compsci 101 spring 2017