COMPUTATION WITH STRINGS 4 DAY 5 - 9/05/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Introduction to Python
Chapter 2 Writing Simple Programs
Python Control of Flow.
UNICODE & CONTROL DAY /24/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Structured programming 4 Day 34 LING Computational Linguistics Harry Howard Tulane University.
ON-LINE DOCUMENTS 3 DAY /17/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
UNICODE DAY /22/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
Structured programming 3 Day 33 LING Computational Linguistics Harry Howard Tulane University.
COMPUTATION WITH STRINGS 2 DAY 2 - 8/29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
SCRIPTS & FUNCTIONS DAY /06/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
TWITTER DAY /07/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
TWITTER 2 DAY /10/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Built-in Data Structures in Python An Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 8 Working.
WEB TEXT DAY /14/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
REGULAR EXPRESSIONS 3 DAY 8 - 9/12/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
REGULAR EXPRESSIONS 4 DAY 9 - 9/15/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
COMPUTATION WITH STRINGS 1 DAY 2 - 8/27/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
REGULAR EXPRESSIONS 2 DAY 7 - 9/10/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
REGULAR EXPRESSIONS 1 DAY 6 - 9/08/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
ON-LINE DOCUMENTS DAY /13/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CONTROL 2 DAY /26/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
TWITTER 3 DAY /12/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )
COMPUTATION WITH STRINGS 3 DAY 4 - 9/03/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CRE Programming Club Class 2 (Import JJZ543 and Practice Your Typing!)
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
CONTROL 3 DAY /29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
String and Lists Dr. José M. Reyes Álamo.
Lists 1 Day /17/14 LING 3820 & 6820 Natural Language Processing
String Methods Programming Guides.
When to use Tuples instead of Lists
CS-104 Final Exam Review Victor Norman.
Lists 2 Day /19/14 LING 3820 & 6820 Natural Language Processing
Flat text Day 6 - 9/12/16 LING 3820 & 6820 Natural Language Processing
Computation with strings 2 Day 3 - 9/02/16
Computation with strings 3 Day 4 - 9/07/16
Section 3.2c Strings and Method Signatures
Intro to PHP & Variables
Computation with strings 1 Day 2 - 8/31/16
CISC101 Reminders Quiz 2 this week.
Regular expressions 2 Day /23/16
control 4 Day /01/14 LING 3820 & 6820 Natural Language Processing
LING 3820 & 6820 Natural Language Processing Harry Howard
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Control 3 Day /05/16 LING 3820 & 6820 Natural Language Processing
NLP 2 Day /07/16 LING 3820 & 6820 Natural Language Processing
String and Lists Dr. José M. Reyes Álamo.
Regular expressions 3 Day /26/16
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CISC101 Reminders Assignment 2 due today.
CHAPTER 4: Lists, Tuples and Dictionaries
Computation with strings 4 Day 5 - 9/09/16
CISC101 Reminders Assignment 3 due today.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Control 1 Day /30/16 LING 3820 & 6820 Natural Language Processing
Introduction to Computer Science
Presentation transcript:

COMPUTATION WITH STRINGS 4 DAY 5 - 9/05/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University

Course organization 05-Sept-2014NLP, Prof. Howard, Tulane University 2   The syllabus is under construction.   Is there anyone here that wasn't here on Wednesday?

Open Spyder 05-Sept NLP, Prof. Howard, Tulane University

Go over homework Review 05-Sept NLP, Prof. Howard, Tulane University

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 § 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. 05-Sept-2014NLP, Prof. Howard, Tulane University 6

A string is a sequence of characters delimited between single or double quotes.string §3. Computation with strings 05-Sept NLP, Prof. Howard, Tulane University

3.6. Dealing with strings that are longer than a line >>> longslash = 'A wonderful bird is the pelican.'\... 'His bill can hold more than his belican.' >>> print longslash 'A wonderful bird is the pelican.His bill can hold more than his belican.' >>> longparen = ('A wonderful bird is the pelican.'... 'His bill can hold more than his belican.') >>> print longparen 'A wonderful bird is the pelican.His bill can hold more than his belican.' 05-Sept-2014NLP, Prof. Howard, Tulane University 8

Strings longer than a line, cont. >>> longsingle = '''A wonderful bird is the pelican.... His bill can hold more than his belican.''' >>> print longsingle A wonderful bird is the pelican. His bill can hold more than his belican. >>> longdouble = """A wonderful bird is the pelican.... His bill can hold more than his belican.""" >>> print longdouble A wonderful bird is the pelican. His bill can hold more than his belican. >>> longdouble 'A wonderful bird is the pelican.\nHis bill can hold more than his belican.' 05-Sept-2014NLP, Prof. Howard, Tulane University 9

Assignment of variable names  You have by now performed an assignment of a variable to an expression several times and hopefully have internalized something like:  variable = expression  This can be read as “variable is assigned to expression”.  For convenience, we often refer to the variable as the name for the expression, though the Python documentation actually prefers identifier to name. 05-Sept-2014NLP, Prof. Howard, Tulane University 10

What's in a name  There are several limitations on what can be a name. The main one is that it cannot be one of the words that Python reserves for its own uses, such as: >>> print = 'print'  A trickier case is that of the methods built into Python, such as the string methods reviewed in this chapter: >>> len = 'len'  Using one of them as a name is not prohibited, but is considered bad form, since it could be confused with the method len() and lead to misunderstanding. Your really do not want to create the possibility of expressions like len(len) in your code. 05-Sept-2014NLP, Prof. Howard, Tulane University 11

What's in a name, cont.  There are also limits on what characters can be part of a name. A name must start with a letter or underscore, but not a digit: >>> name = 'zzz' >>> _name = 'zzz' >>> 0name = 'zzz'  Once a name has been started correctly, it can contain any combination of letters, digits, or underscores, but nothing else: >>> my_name = 'zzz' >>> my_name1 = 'zzz' >>> my name = 'zzz' >>> my-name = 'zzz'  Upper and lower case are different: >>> name = 'zzz' >>> Name = 'zzz2' >>> name == Name 05-Sept-2014NLP, Prof. Howard, Tulane University 12

Mutability  Try these: >>> name[0] = 'b' >>> del name[0]  Strings are immutable, which is to say, once a string has been created, it cannot be changed by adding or deleting items from it.  The only way that it can be changed is by means of the methods that were reviewed above. 05-Sept-2014NLP, Prof. Howard, Tulane University 13

Q1 as take home to turn in in class on Monday §4 Lists Next time 05-Sept-2014NLP, Prof. Howard, Tulane University 14