cps6-111108Handout

cps6-111108Handout - Special symbols [ ] + % Regular...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger Announcements • No reading or RQ • Assignment 5 due Thursday • New APT out Thursday – one APT • Practice Test problems out – will go over on Tues. Nov 15 • Prof. Rodger no office hours this week • Today – Finish example from last time – More on sort options – Regular Expressions More on sort • Import operator – fruit = [(“pear”,5),(“apple”,9)] • fruit = sorted(fruit) • fruit.sort() OR fruit = sorted(fruit) – arguments • key=itemgetter(0) • reverse=True Regular Expressions • Part of the compiler process – Can write a regular expression for each type of word in a programming language –Examp le • Key words – if, else, elif, while • Integers – 456, 78, 2, -56 • Float – 3.14, 7856.2345
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Special symbols [ ] + % Regular Expressions a- a a* - a repeated 0 or more times a+ - a repeated 1 or more times a? a 0 or 1 time, so a is optional ^ - match at the beginning of the string $ - match at the end of the string . matches anything [abc] match a, b, or c [a-z] match any character from a to z [^a] match any character but a More on regular expressions | - or \b - word boundary \s - whitespace character \d match any digit When using backslashes must use r in front of string Regular expressions with re import re re.sub() substitute re.compile() create a pattern re.findall() See examples...
View Full Document

This document was uploaded on 01/17/2012.

Page1 / 2

cps6-111108Handout - Special symbols [ ] + % Regular...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online