New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here


by: Ransom Blanda


Ransom Blanda
GPA 3.63

Ana Milanova

Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Ana Milanova
Class Notes
25 ?




Popular in Course

Popular in ComputerScienence

This 8 page Class Notes was uploaded by Ransom Blanda on Monday October 19, 2015. The Class Notes belongs to CSCI 4430 at Rensselaer Polytechnic Institute taught by Ana Milanova in Fall. Since its upload, it has received 59 views. For similar materials see /class/224843/csci-4430-rensselaer-polytechnic-institute in ComputerScienence at Rensselaer Polytechnic Institute.

Similar to CSCI 4430 at RPI

Popular in ComputerScienence




Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/19/15
Announcements HW4 Due Tuesday April 14th Project 3 Python and Java Will be posted April 14th Due April 28th Python infrastructure Fr BSDs or download from wwwpythonnrg Java infrastructure FreeBSDs or download an IDE such as Eclipse sorrnd us 60 Man A MllenayaBG Ryder Announcements ii A slight change in schedule Today Scripting Languages and Python From next class on Objectoriented programming Java Concurrency in Java sorrnd us 60 Man A MllenayaBG Ryder Announcements iii Final Exam May 5th 36pm Final Exam Topics Exam is cumulative About40 on premidterm material About 60 on remaining material Functional programming and Scheme SclO Lambda ca culus D straction Types Sc71 7 771 Control abstraction Paramete Passing 8183 Scr39pting languages md Py on TED Objectsorienm larguages md Java TBD Concurrency Comparative programming lmguages 55 at sorrnd us 60 Man A MllenayaBG Ryder Last Class Parameter Passing Parameter Passing Mechanisms Call by value Call by reference Call by result Call by valueresult Call by name sorrnd us 60 Man A MllenayaBG Ryder Scripting Languages Python Read Optional Scott Chapter 13 Topics Scripting Programming Languages Taking Stock PL Design Choices Python Syntax and scoping Datatypes Control flow constructs The Python Style Modules as and re modules sorrnd us 60 Man A MllenayaBG Ryder Scripting Programming Languages Eg Perl Tcl Python Ruby VBScript AppleScript Originate in the 1970 s from UNIX shell scripts Purpose To process text les with ase To launch components and combine or gluequot these components into an application Characteristics Ease of use exibility rapid prototyping hence scripting lang uags are dynamically typed Extensive support r text procssing Svrlnq us ca Man A MllenayalBG Ryder 7 Python Designed by Guido van Rossum at CWI Amsterdam in early 1990 s Multiparadigm programming language All characteristics of scripting languages It has functional features Eg higherorder functions list comprehensions It has objectorientedquot features Eg iterators array slicing operations re ection exceptions multiple inheritance dynamic loadin Svrlnq us ca Man A MllenayalBG Ryder a Taking Stock Design Choices Datatypes Controlnflow Bas c Operation Svrlnq us ca Man A MllenayalBG Ryder 9 Taking Stock Design Choices ii Varl able Model P359 quot9 Scoplng Typlng Mecharllsrn Scheme Reference 5V Value Static nested Dwamc nodel function strong de nltiorls Java Value model BY Vame Stem no Stem for slrrple types nested 5W9 reference nodel or class types de n mns C Value model Ev vaflue and 322 Stem y re ererlce ul lctiol l weak de nlnorls 5Win HQ 60 Man A MlianayalBG Ryder m Syntax and Scoping 5w P 725 Variable belon s to block where it is 221320 written unless explicitly im orted def middle What Is the output of this program def 1nne z bal m u from mam program not outer m print mjk innero retum mjk u 3 element tuple 2 it new local m retum middleu a old global Print one What39s printed if we remove Prim quot3 the red global mquot statement the blue assignment statement SDrlanQ 61443URMllanayaBG Ryder 11 Scoping Common Indentation Error pythongtpython scopepy File quotscopeDYquot line 10 m2 new local m IndentationError unindent does not match any outer indentation level Svrlnq us ca Man A MllenayalBG Ryder 12 Scoping Static Scoping Rules Blocks scopes are defined by indentation There are no variable declarations A variable belongs to block where it is written Closest nested scope rule applies Lookup proceeds from inner to outer blocks global39 overrides rule for access to outermost Spring us 60 Man A mamaac Rvdev 13 Datatypes Numbers pow etc immutable Collections Sequences Strings immutable Lists Tuples immutable Mappin s Dictionaries Files Spring us 60 Man A mamaac Rvdev n Datatypes Strings Strings Immutable Eg spam spam Operations concatenation repetition Li index into Lik slice en length for x in 2 iteration Spring us 60 Man A mamaac Ryder 15 Datatypes Strings ii examples of stung operatlonst a samam punt a 1ena asauuan s for c n a punt c apunts eacn char 1 per llne o a I m Sam aquotrng an nner quote mark n a stung c a a i i i aconcaten Jon punt c asauuan I m Sam d a a t 4 astung re eat punt d asamansamansamausaman ndexlng and sllclng of strlngs punt are an as m selects Jndlvldua elements punt a02 a35 asa 1a shoes lower bound ncluslve aupper bound NOT ncluslve punt am a3 asa Jam default start at posltlon o adetauits to end of stun liexphclt coerclons stro nt 1quot Spring us 60 Man A mamaac Ryder 16 Datatypes Lists Lists Mutable Eg 1 2 1 2 3 4 Operations As on string 139 1k en forx in L append appends element to list reverse reverss sort sorts Spring us 60 Man A mamaac Rvdev n Datatypes Lists ii see how nsts use sane operators as stungs x 1 2 prlnt x0x1 an 21 t xti l I 1 2 punt X y am 2 3 3rreverse cnanges 11st 1n place adoesn39t return a bet returns None 2 nt x M4 3 2 x sorto nt x M2 3 4 Spring us 60 Man A mamaac Rvdev m Datatypes Tuples Tuples Immutable Similar to lisB except that it is immutable Eg 1 39john39 3 mary39 Operations As on string 139 1k len forx in L Spring us at man A MilanavaBG My 19 Datatypes Dictionaries Dictionaries also called associative arrays Eg d spples 10 39oranges39 5 39pears39 1 39tangerlnes39 2 Operations dvalues dkeys dhaskey apple Etc Spring us at man A MilanavaBG My 2n Datatypes Dictionaries ii d 39apples39 10 39oranges 39pears39 1 Itangennes 2 pnnt d39oranges39 us pnnt d tangerlnes 2 pears 1 appes 10 oranges 5 pnnt dikeysO l tangerlnes pears apples oranges 1 pnnt divaluesO m2 1 10 5 pears39 mus pnnt dines ey39aprlco39 psise d pnnt d tangerlnes s2 pears 6 appes 10 oranges 5 del dl39applesJ pr t d Nl tangerlnes 2 pears 5 oranges s pnnt lend a Spring us at man A MilanavaBG Ryder 21 Datatypes Dictionaries iii z apples ul plums 2 ztupdatew anote overwrlte of apples value from a prlnt z oranges 5 pears 6 pums 2 appes 10 tangernes 2 punt out table by teratlng over 1 keys set anges s A prlnt frult t zfrut Spring us at man A MilanavaBG Ryder 22 Datatypes Files apractuce mtn flle objects output open csman0VaPyth0ntemp w nput open csmlanovaPythonlntemp 1 nputi open csmlanovaPythonlntemp 1 s nputtreadOi th5 s a Elle of sentences alto be used as data for a python program Juana tnput2treadnei th s a Elle of sentences tnput2treadnei pm t alto be used as data for a pytnon program outputtwrltes t t m t Dataypes Files ii nyme open myfe w Myflletwrlte hello wordn MuflletcloseO nyme open myfe r Myflletreadhneo aneno world Myflletreadhneo 1quot empty strlng means end of me Spring us at man A MilanavaBG My 24 Datatypes So what model for variables does Python use Reference model for variables May have result in unexpected values due to aliasing Equality equal in value structural equality value equality is same object reference equali None acis like null in C a placeholder for an actual value Spring us 60 Man A mamaac Ryder Datatypes Common Errors Updates to shared references A1IZ B1A A10 changes B also 3 YL3 maks 456456455 an makes Y 455456456 Cyclic data structures L hello LappendL L becomes hello39 Immutable types cannot be assigned to T 12 T14 ERROR TT14 OK Spring us 60 Man A mamaac Ryder Control Flow Shortcircuit evaluation of boolean exprssions Constructs for conditional control f x Ana 2 1f print found Ana39 ell x Mary z print found Mary e sex print missing key39 print done OWIif z z Spring us 60 Man A mamaac Ryder Control Flow ii Constructs for looping while x Y while x1 matches else belowshown by indenting If x 2 print y has factor x break sklps the else x xl else print y is pr ed even if loop body isn39t is execut me Spring us 60 Man A mamaac Ryder Constructs for looping for for x in spa quot eggs print x iterates over list elements hamquot s 1umberjack for y in 5 print y iterates over chars Control Flow iii Functions Two forms of function definition def incr A return M iii notion incr x xa lambda x x2l Polymorphism awnat datatypes can this functlon be used on def ectseq1 seqi s for x in seq iiiterates over elements in 5qu i x in seqi iicnecks 1f element is in 5qu resrappendbt air so adds element to list return res Comments delimited by anywhere on a line print intersectl23l24sl M2 print lntersect 1234 435 341 print intersectlt 123 1231 Ml 2 3 print lntersect1 a 2 b 3 c 1 E 42 d 1 print lntersect1 a 2 b 3 c At a 5 b M iiclearly the intersection is on the keys not the valuesl Spring us 60 Man nMiianavaBG Ryder 29 3D Functions ii What is the parameter passing mechanism in Python Call by value Or call by sharin But be careful value is a reference If reference to a mutable object callee can change object sprmd us 60 Man A MllenavaBG Ryder 31 Python Style Use of Iterators L1248163264 1248163264 x 5 I o whxle I lt 1enL 1f zux LII pan 3 index I break lsez print x not foundquot I I1 else pnm x not foundquot Note there ls a problem Wli the program on the left Carl you apotrt7 mere ls a problem Wldn the programorl me rlght mo Carl you apotrt7 sprmd us 60 Man A MllenavaBG Ryder 32 Python Style Iterators ii M115 let s look at terat r a used 1n 1oopmg mnput open csman0vaPyth0n1ntemp r n o for llne n open ntemp new prlnt n hue lloutput in true 5 nput for my Ellerpy program in there 5 not much else to say about 1 ll 13 Ana SDvlanQ 60 mm AMllenayaBG Ryder 33 Python Style Iterators iii llaecona example 5 how to create an terator expllcltly mth Jtero s o l t e ters prlnt 1t lklterator object at 0x674b0gt prlnt Jtrnexto lla prlnt Jtrnexto lab prlnt trnexto llc prlnt trnexto llcauaea an exceptlon to occur arraceoack moat recent call last ll m e terAPY hue 17 n ll prlnt trnexto lltma causes Stoplteratlon exceptlon to occur astoplteration sprmd us 60 Man A MllenavaBG Ryder 34 Running Python Interactiver or using commands stored in a file Interactively Type Python commands Indenting at the prompt will have unforeseen consequences File Python module Use py lename extension Can make les executable scripis under Unix First line must be in ltpa 1 m python inmrpremrgt File needs exemmble privilege sprmd us 60 Man A MllenavaBG Ryder 35 Python Modules os module interfaces to the operating system How to walk a directory lulpor as for root curs les in ostwalk39csmllanovapyhonesHand1n39 z pnn quot zoo ooquotn any quot d in it sprmd us 60 Man A MllenavaBG Ryder 36 How to walk a directory ii cslmlanovapythontest andin prolog Scheme python csmi1anovapythontestHandinprolog peter ana root csmi1anovapythontestHandinprologpeter 1 pro 1 pro 2 csmi1anovapythontestHandinprologana ry iles i1e2 i1e1 sprrnd us 60 mn R MiianayaBG Ryder 37 How to walk a directory iii root csmi1anovapythontestHandinScheme diry atarina ana k Eiles root csmi1anovapythontestHandinSchemeana di iles i1e1 i1e2 i1e3 oo dlry iles project csmi1anovapythontestHandinSchemekatarina root cslmilanovapythontestHandinpython dirya Eiles sprrnd us 60 mn R MiianayaBG Ryder 35 Regular Expressions in Python re module reguiarexprssion functionality Pattern constructors r rhg 3 Matdnes end of strhg Gust be 0 Aaaz s hy nonraiphabeucsymboi i AiB where AB are reguiar expressions means A or B es med rrorn iertto rrght h i expression 5 rrrathes ahy Whimspace character d rrraches 079 sprrnd us 60 mn R MiianayaBG Ryder 39 Exlsimplc substitution addrspy cr brye We Pyrhorr Wigwam151m 39Aranue39mre Ruad39mu and reet 5L my In 40 Mi mm ragaa erpressvbns n Pyb mn import re ma module f1open c5mlanovapythonaddrsrln f2open csmlanovapythonaddrsrout for llne n f as 1 pattern means end of string rersubm ROADS r aauiine prlnt 11116 x for llne n 2 x reisub39bRDAD39 men line Mb requires word to start at tn39 i y reisubr39bROAD39 39Rdr39 line r is raw string d pr scapes due to backs1asnes z reisubr39bROADb39 39Rdr39 line new pattern does not require Rom to be at end of string print 1inexy z c u u o 1 n sprrnd us 60 mn R MiianayaBG Ryder m cf bryz We Python addrsout 100 FALLS ROAD t 10 100 FALLS ROAD 10 FALLS ROAD Output excerpls 100 BROAD ROAD 100 BROAD Rat pattsrn worked and didn t change ROAD in snow 100 FALLS ROAD Apt 10 t 10 apattern falled 100 FALLS ROAD 10 FALLS ROAD 100 FALLS ROAD 10 FALLS Rat apattern worked on last ROAD 100 FALLS ROAD 10 FALLS ROAD sprrnd us 60 mn R MiianayaBG Ryder 41 Ex2 forming and using patterns and matches print st eabea aabbaabb a reicomler39 a39 creates pattern a pattisearchw searches for pattern in string s 1 no match re ms 0 0 else print what matched pattern aa iconpll punt paEEZisearchsigrou a punt paEEZisearchuHigroupO 33 for matchohj in patt2i 1ndlter t print matchobjiendo prints 2 and 6 sprrnd us 60 mn R MiianayaBG Ryder 42 Ex2 forming and using pa zr ns and mafchzs pa3ecomp11e39 Pltx1gta Pltx2gtb 39 pan pa3seazchs groupquotx1quota p uu paEEB seachs gzoupvxzIwnone for matchobj m pacczjmduezmz pxlnt matchobj ndo pnncs 2468 Swan us ca Man A M armvaBG My


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.