Download presentation
Presentation is loading. Please wait.
Published byJemima Skinner Modified over 9 years ago
1
COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University
2
Course organization 03-Sept-2014NLP, Prof. Howard, Tulane University 2 http://www.tulane.edu/~howard/LING3820/ http://www.tulane.edu/~howard/LING3820/ The syllabus is under construction. http://www.tulane.edu/~howard/CompCultEN/ http://www.tulane.edu/~howard/CompCultEN/ Is there anyone here that wasn't here on Wednesday? Take pictures.
3
Measure heads 25-Aug-2014 3 NLP, Prof. Howard, Tulane University
4
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
5
Go over homework Review 03-Sept-2014 5 NLP, Prof. Howard, Tulane University
6
3.5. Practice 1. What types are output by len(), sort(), set()? 2. Here are two real life strings to work with: >>> mail = howard@tulane.edu >>> url = http://www.tulane.edu/~howard/CompCultEN/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
7
3.5. Practice, cont 3. 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
8
3.5. Practice, cont 4. 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
9
Finish homework & §3 Next time 03-Sept-2014NLP, Prof. Howard, Tulane University 9
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.