File Processing Recap String Processing Review Escape Sequences
- Slides: 27
File Processing Recap
String Processing: Review Escape Sequences: print the unprintable '<symbol>': escape sequence 'n': newline 't': tab '"': " >>> print 'Hellon. World' Hello World >>> x = eval('40n') x = 40
File Processing Review: Open File >>> infile = open('myfile. txt', 'r') >>> outfile = open('myfile. txt', 'w') Manipulate File Read Write Close File >>> infile. close()
File Processing Review: Writing outfile. write(<string>) Reading infile. read() infile. readlines() infile. readline() myfile. txt Spam and Eggs >>> infile = open('mytext. txt', 'r') >>> x = infile. read() >>> x 'Spamnandn. Eggsn'
File Processing Review: Starts from last line read myfile. txt >>> x = infile. readline() >>> x 'Spamn‘ Spam and Eggs >>> x = infile. readlines() >>> x ['andn', 'Eggsn‘] To start from the beginning of the file, need to close and reopen
End of the File? . read(), . readlines(): read until end of file . readline()? Empty string ('') x = 'stuff' while x != '': x = infile. readline() print x Files are sequences! for line in infile: <process the line> Spam and Eggs
Recursion
Rock, Paper, Scissors def main(): # define items # Player and Computer make their selection. . . # inform Player of choices # figure out who wins # print out results of the game main() # invoke the program
Rock, Paper, Scissors def main(): # define items # initialize score # Player and Computer make their selection. . . # inform Player of choices # figure out who wins and update score # print out results of the game main() # invoke the program
Rock, Paper, Scissors # initialize score def main(): # define # Player # inform # figure Recursion items and Computer make their selection. . . Player of choices out who wins and update score # ask if user wants to play again if play_again == 'Y': main() else: # print out results of the game main() # invoke the program
Recursion Function being defined is invoked within its own definition Usually do not recurse main
Rock, Paper, Scissors # initialize score def main(): # define # Player # inform # figure items and Computer make their selection. . . Player of choices out who wins and update score # ask if user wants to play again if play_again == 'Y': main() else: # print out results of the game main() # invoke the program
A Better Recursive Solution. . . def playgame(score): # Player and Computer make their selection. . . # inform Player of choices # figure out who wins and update score # ask if user wants to play again if play_again == 'Y': playgame(score) else: # print out results of the game def main(): # define items # initialize score playgame(score) # play the game main() # invoke the program
Recursion Some problems can only be solved with recursion: 3! = 3 Factorial = 3 * 2 * 1 = 6 n! = n * (n – 1) * (n – 2) *. . . * (n – (n - 1)) 1! = 1, 0! = 1 def factorial(n): if n <= 1: return 1 else: return factorial(n-1)
Recursion def factorial(n): if n <= 1: return 1 else: return n * factorial(n-1) def main(): factorial(4) Stack factorial(1) factorial(2) factorial(3) main() factorial(4) A lot of overhead main()
Rock, Paper, Scissors def main(): # define items # initialize score # Player and Computer make their selection. . . # inform Player of choices # figure out who wins and update score # print out results of the game main() # invoke the program
A Better Solution def main(): # define items # initialize score done = 'N' while done == 'N': # Player and Computer make their selection. . . # inform Player of choices # figure out who wins and update score # ask if user wants to play again # print out results of the game main() # invoke the program
Multivariate Data CMSC 120: Visualizing Information Lecture 4/17/08
Types of Analysis Univariate Bivariate A single attribute Two attributes Characterize Observations Number Type Similarity Describe Associations How variables simultaneously change together Are two groups the same? Is there a relationship? What is the nature of the relationship?
Bivariate Analysis How two variables co-vary How two variables are correlated Describes a how a change in one variable is related to a change in another Relationships are not causal!
Bivariate Analysis How two variables co-vary Describes the degree of similarity between two variables (X, and Y) Measure of how two variables vary together about the mean How two variables are correlated Indicates strength and directionality of a linear relationship between X and Y Departure of relationship from independence
Lizard Plant Lizard 10. 1 8. 4 Plant 8. 4 12. 0 25 20 15 Plant Diversity 10 -15 5 0 -10 Correlation -5 0 5 10 15 -5 -10 -15 -20 X Y X Variance Covariance Y Covariance Variance Lizard Diversity
Multivariate Data 3 or more variables Extension of Bivariate Relationships among Variates
Multivariate Visualization
Projection Image of an imaginary multi-dimensional object is projected on a planar (2 -D surface) Mathematical calculation
Projection Image of an imaginary multi-dimensional object is projected on a planar (2 -D surface) Mathematical calculation
Projection Image of an imaginary multi-dimensional object is projected on a planar (2 -D surface) Mathematical calculation Distort the data
- Licenseid=string&content=string&/paramsxml=string
- Escape sequence in c
- File-file yang dibuat oleh user pada jenis file di linux
- Const char * vs char * const
- Private string name
- 3600000/24
- C string review
- Physical image vs logical image
- Fungsi dari create file pada operasi-operasi file (cont.)
- Remote file access in distributed file system
- An html file is a text file containing small markup tags.
- In a file-oriented information system, a transaction file
- Shawshank redemption summary
- Chapter 8 summary the great gatsby
- Segmented pricing
- What is the purpose of an iteration recap
- Recap intensity clipping
- 60 minutes recap
- Recap database
- Differentiation recap
- Sample script for recapitulation
- Recap introduction
- Recap from last week
- Act 4 the crucible discussion questions
- What theological argument does john
- Logbook recap example
- Ytm recap
- Black box recap