CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists

Similar documents
CSE 111 Bio: Program Design I Lecture 17: software development, list methods

CS 111: Program Design I Lecture 14: Encodings & Files concluded; Pandas, Modules, legal data analytics

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

CS 111: Program Design I Lecture 20: Web crawling, HTML, Copyright

CS 111: Program Design I Lecture 21: Network Analysis. Robert H. Sloan & Richard Warner University of Illinois at Chicago April 10, 2018

CS 111: Program Design I Lecture 19: Networks, the Web, and getting text from the Web in Python

Lecture 9: Exam I Review

CS 111: Program Design I Lecture 15: Modules, Pandas again. Robert H. Sloan & Richard Warner University of Illinois at Chicago March 8, 2018

CS 11 C track: lecture 1

Python Programming: An Introduction to Computer Science

CSE 111 Bio: Program Design I Class 11: loops

Python Programming: An Introduction to Computer Science

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

CS 111: Program Design I Lecture #26: Heat maps, Nothing, Predictive Policing

CMPT 125 Assignment 2 Solutions

Computers and Scientific Thinking

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts

How do we evaluate algorithms?

The number n of subintervals times the length h of subintervals gives length of interval (b-a).

CS 111: Program Design I Lecture 5: US Law when others have encryption keys; if, for

CS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8)

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

CS 111: Program Design I Lecture 20: Web crawling, HTML, Copyright

Exceptions. Your computer takes exception. The Exception Class. Causes of Exceptions

CS 111: Program Design I Lecture 18: Web and getting text from it

Lecture 1: Introduction and Strassen s Algorithm

3. b. Present a combinatorial argument that for all positive integers n : : 2 n

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

Arithmetic Sequences

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

. Written in factored form it is easy to see that the roots are 2, 2, i,

Exercise 6 (Week 42) For the foreign students only.

CS 683: Advanced Design and Analysis of Algorithms

n n B. How many subsets of C are there of cardinality n. We are selecting elements for such a

CS200: Hash Tables. Prichard Ch CS200 - Hash Tables 1

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Analysis of Algorithms

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Homework 1 Solutions MA 522 Fall 2017

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Message Integrity and Hash Functions. TELE3119: Week4

IMP: Superposer Integrated Morphometrics Package Superposition Tool

top() Applications of Stacks

Math Section 2.2 Polynomial Functions

Administrative UNSUPERVISED LEARNING. Unsupervised learning. Supervised learning 11/25/13. Final project. No office hours today

CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago

Ones Assignment Method for Solving Traveling Salesman Problem

Our Learning Problem, Again

Examples and Applications of Binary Search

Module 8-7: Pascal s Triangle and the Binomial Theorem

Lower Bounds for Sorting

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

K-NET bus. When several turrets are connected to the K-Bus, the structure of the system is as showns

Lecture 5. Counting Sort / Radix Sort

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

One advantage that SONAR has over any other music-sequencing product I ve worked

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

Data Structures and Algorithms. Analysis of Algorithms

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Analysis of Algorithms

CSE 417: Algorithms and Computational Complexity

Parabolic Path to a Best Best-Fit Line:

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Switching Hardware. Spring 2018 CS 438 Staff, University of Illinois 1

Random Graphs and Complex Networks T

1 Graph Sparsfication

The isoperimetric problem on the hypercube

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions

Data Structures Week #9. Sorting

Pattern Recognition Systems Lab 1 Least Mean Squares

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer

Normal Distributions

WORKED EXAMPLE 7.1. Producing a Mass Mailing. We want to automate the process of producing mass mailings. A typical letter might look as follows:

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

condition w i B i S maximum u i

Computational Geometry

Weston Anniversary Fund

CIS 121. Introduction to Trees

l-1 text string ( l characters : 2lbytes) pointer table the i-th word table of coincidence number of prex characters. pointer table the i-th word

CHAPTER IV: GRAPH THEORY. Section 1: Introduction to Graphs

LU Decomposition Method

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Mathematics. Programming

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Transcription:

CS 111: Program Desig I Lecture 16: Module Review, Ecodigs, Lists Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 18, 2016

Last time Dot otatio ad methods Padas: user maual poit of view modules

Today Modules: Review with oe more example Ecodigs Lists

MODULES: REVIEW, 1 MORE EXAMPLE (RANDOM)

Modules import to make it available access it through the dot otatio (like methods) We'll briefly look at oe iterestig module that is from the stadard library: radom

A iterestig module: radom >>> import radom >>> for i i rage(5):... prit(radom.radom())... 0.12636664029165268 0.2821272889535512 0.6160031940187543 0.28609006981908525 0.6277074518401735 Notice: We're usig the fuctio amed radom from the module amed radom, hece radom.radom()

Radomly choosig words from a list >>> for i i rage(5):... prit(radom.choice(["here", "is", "a", "list", "of", "words", "i", "radom", "order"]))... list words i Here list

How ofte do you look at xkcd A Ususally or always B Oce i a while C Never D I've ever heard of xkcd

Radomly geeratig laguage Give a list of ous, verbs that agree i tese ad umber, ad object phrases that all match the verb, We ca radomly take oe from each to make seteces.

import radom def excuse(): excuse = ["I did't kow I was i this class", "I thought I already graduated", "I got stuck i a blizzard"] bignum = ["4", "17", "like a billio", "mega", "tos of"] lottawork = ["midterms", "Ph.D. theses", "programs"] prit ("I eed a extesio because", radom.choice(excuse), "ad I had", radom.choice(bignum), radom.choice(lottawork), "to do.") Side ote: Good example of a fuctio that should have 0 iputs ad o retur value.

Ruig radom setece geerator >>> excuse() I eed a extesio because I thought I already graduated ad I had like a billio programs to do. >>> excuse() I eed a extesio because I got stuck i a blizzard ad I had 4 programs to do. >>> excuse() I eed a extesio because I got stuck i a blizzard ad I had 17 programs to do. >>> excuse() I eed a extesio because I thought I already graduated ad I had tos of programs to do. >>> excuse() I eed a extesio because I did t kow I was i this class ad I had 17 Ph.D. theses to do.

Questios about lab or homework?

ENCODINGS

Ecodigs agai Recall that the smallest uit i a computer is the bit Oe bit ca take o 2 possible values: 0 or 1 Two bits ca take o 4 possible values: 00, 01, 10, or 11 Three bits ca take o 8 possible values: 000, 001, 010, 011, 100, 101, 110, 111

How may distict values ca 4 bits take o? A. 4 B. 8 C. 9 D. 13 E. 16

Be Bitdiddle says bits ca take o 2 times as may values as -1 bits = 2 values

How may distict values ca a byte take o (Recall that a byte = 8 bits) A. 2 B. 8 C. 64 D. 128 E. 256

Ecodig characters i bytes ASCII: Use 1 byte to ecode 95 pritig characters The oes o every computer keyboard to this day Pretty much all ecodigs agree with ASCII o those 95 characters

But What about Vigeère? А что насчет Aрабского?

Ecodig more characters Uicode: over 128,000 characters coverig 135 moder ad historical scripts, ad symbols 2 bytes ot eough for all of it q 2 16 is "oly" 65,536 Various character ecodigs for all or a subset Pytho supports Uicode

Ecodigs of files i Uicode Two fairly commo ecodigs of Uicode (i.e., bit patter character correspodeces) q q UTF-8 (Pytho's default guess): multi-byte, variable umber of bytes (1 4 bytes/character) ISO-8859-1: 1 byte, so ca ecode limited # of characters; i fact ecodes Lati-1 ASCII plus most acceted characters plus commo symbols: 195 characters covers all of Eglish ad may commo Europea laguages ½¼ ± ÀÁÂÃÄ Æ Ç ÈÉÊË Ø àáâãäå æ ç èé N.B. Oly a issue for files

Which ecodig? It's pretty uusual to eed to give Pytho the ecodig argumet whe opeig a file Pytho defaults to UTF-8, which agrees with ASCII o ASCII characters, ad most text files are ASCII Ad very may of the rest are UTF-8 But some are ISO-8859-1 q For websites, about 5 or 6%

Supreme Court Database that we are workig with is ISO-8859-1 q Almost etirely ASCII characters, but uses symbol i places

LISTS

Next big project: Fiish Web Crawler We will eed to make more extesive use of lists tha we have up util ow Recall our strategy is goig to be somethig like

Crawl all pages reachable from start List of pages to visit, iitially start while that list is ot empty: q Take a page from the list q Get its text # eed to lear how to do this q q q remove that page from to-visit list, add it to already-visited lst Get all the liks i that page for each lik if ot already i visited list add it

Ad besides Lists i Pytho are just awesome

Lists versus Strigs List Elemets ca be ay type Mutable Heterogeeous elemets Ca be ested i other lists Strig Elemets are characters Immutable Homogeous elemets

Recall Lists are data structures that let us store collectios of data i sequece with idices

Remember the smallest "" # Empty strig, could also be writte '' [] # empty list

A = [2,3,5] B = ["Brea"] C = A + B prit(c) will result i: A. [2,3,5] B. [2,3,5,"Brea"] C. ["2","3","5","Brea] D. This will cause a error E. I do t kow

List Fuctios These are ot methods; there are also list methods, e.g., apped le: legth of a list (i.e., umber of elemets) + will cocateate lists mi, max: miimum or maximum of list sum: sum of the elemets i the list q E.g., sum([2, 3, 5]) à 10

Importat: Lists are mutable >>> years= [1788, 1800, 1860, 1932] >>> years[0] = years[0] + 4 >>> prit(years) [1792, 1800, 1860, 1932]

What is prited lst = ['abc.com', 'c.com', 'msbc.com'] lst[1] = 'fox.com' prit(le(lst)) A. 3 B. 4 C. 23 D. 30 E. No output; error i 2 d lie of code

What is prited lst = ['abc.com', 'c.com', 'msbc.com'] lst[1] = 'fox.com' ow lst has become ['abc.com', 'fox.com', 'msbc.com'] prit(le(lst)) A. 3 B. 4 C. 23 D. 30

What will this output? def ic(ls, x): x = x + 1 for i i rage(le(ls)): ls[i] = ls[i] + 1 ls = [2, 6, 7] x = 5 ic(ls, x) prit(ls, " ", x) Clicker prit(ls, " ", x) A [2,6,7] 5 B [3,7,8] 6 C [3,7,8] 5 D [2,6,7] 6 E I do t kow

Parameter passig (review, Chapt. 6.3) Recall: Assigmet statemet iside fuctio creates local variable q Distict object from ay outside fuctio; exists oly iside fuctio; ca't be used outside Ad formal parameters of fuctios are also local variables That's all there is to thik about ad all that's worth kowig about local variables q As log as a referece to immutable object is what is passed i as actual parameter

Parameter passig: lists as actual parameters Passig list as argumet to fuctio passes referece to that list, ot a copy q Chages made by fuctio will be visible afterwards i caller's scope! Fuctios that chage lists passed to them as parameters called modifiers; chages they make are called side effects (of callig the fuctio)