computation with strings 3 day 4 - 9/03/14 ling 3820 6820 natural language processing harry howard...

9
Computation with strings 3 Day 4 - 9/03/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University

Upload: jemima-skinner

Post on 18-Jan-2018

218 views

Category:

Documents


0 download

DESCRIPTION

Measure heads 25-Aug NLP, Prof. Howard, Tulane University

TRANSCRIPT

Page 1: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

Computation with strings 3Day 4 - 9/03/14LING 3820 & 6820Natural Language ProcessingHarry HowardTulane University

Page 2: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

Course organization

03-Sept-2014NLP, Prof. Howard, Tulane University

2

http://www.tulane.edu/~howard/LING3820/

The syllabus is under construction. http://www.tulane.edu/~howard/CompCu

ltEN/ Is there anyone here that wasn't here on

Wednesday? Take pictures.

Page 3: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

Measure heads

25-Aug-2014

3

NLP, Prof. Howard, Tulane University

Page 4: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

Computer hygiene You must turn

your computer off every now and then, so that it can clean itself.

By the same token, you should close applications every now and then.

03-Sept-2014

4

NLP, Prof. Howard, Tulane University

Page 5: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

Go over homework

Review

03-Sept-2014

5

NLP, Prof. Howard, Tulane University

Page 6: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

3.5. Practice1. What types are output by len(), sort(), set()?2. Here are two real life strings to work with:>>> mail = [email protected]>>> url = http://www.tulane.edu/~howard/CompCultEN/

a. How would you strip out the user name and the server name from my email address?

b. Internet addresses start with the transfer protocol that the site uses. For web pages, this is usually the hypertext transfer protocol, http. How would you strip this information out to leave just the address of the book?

c. Following up on (b), how would you extract just Tulane’s server address?

03-Sept-2014NLP, Prof. Howard, Tulane University

6

Page 7: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

3.5. Practice, cont3. Write the code to perform the changes given

below on these two strings:>>> S = 'ABCDEFGH'>>> s = 'abcdefgh'

a. Make the first 3 characters of S lowercase.b. Make the last 4 characters of s uppercase.c. Create a string from the first 4 characters of S and

the last 4 characters of s and then switch its case.d. Join both strings and find every even character.e. Join both strings and reverse the order of the

characters.f. Retrieve the index of ‘E’ and ‘h’.

03-Sept-2014NLP, Prof. Howard, Tulane University

7

Page 8: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

3.5. Practice, cont4. What is the longest sequence of operators that you can

make?5. Show which of len(), sort(), and set() takes the most time

to process.6. Line 2 from the previous subsection has the expression

L[2:6].capitalize().upper(). Show whether it is faster for Python to process this as it is, or broken into its parts as in:>>> A = L[2:6]>>> B = A.capitalize()>>> C = B.upper()

7. Recall the discussion of the default precedence of * and + in §3.1.1. Perhaps * comes first because it is quicker to process than +. Test this hypothesis by writing a function for either combination of * and + and time them to see which runs faster.

03-Sept-2014NLP, Prof. Howard, Tulane University

8

Page 9: COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820  6820 Natural Language Processing Harry Howard Tulane University

Finish homework & §3

Next time

03-Sept-2014NLP, Prof. Howard, Tulane University

9