Think Python: How to Think Like a Computer Scientist
Random Words To choose a random word from the histogram, the simplest algorithm is to build a list w ...
Markov Analysis If you choose words from the book at random, you can get a sense of the vocabulary, but you pr ...
Exercise 13-8. Markov analysis: 1 . Write a program to read a text from a file and perform Markov anal ...
Data Structures Using Markov analysis to generate random text is fun, but there is also a point to ...
benchmarking. A practical alternative is to choose the data structure that is easiest to implement, and then ...
Debugging When you are debugging a program, and especially if you are working on a hard bug, there are five ...
possibilities, try to think of a test that would eliminate one of them. But even the best debugging te ...
Glossary deterministic: Pertaining to a program that does the same thing each time it runs, given the ...
Exercises Exercise 13-9. The “rank” of a word is its position in a list of words sorted by frequency: ...
...
Chapter 14. Files This chapter introduces the idea of “persistent” programs that keep data in permanen ...
Persistence Most of the programs we have seen so far are transient in the sense that they run for a sh ...
Reading and Writing A text file is a sequence of characters stored on a permanent medium like a har ...
Format Operator The argument of write has to be a string, so if we want to put other values in a file, ...
powerful alternative is the string format method, which you can read about at https://docs.python.org/3/library/std ...
Filenames and Paths Files are organized into directories (also called “folders”). Every running program has a “cu ...
def walk(dirname): for name in os.listdir(dirname): path = os.path.join ...
Catching Exceptions A lot of things can go wrong when you try to read and write files. If you try to open ...
Databases A database is a file that is organized for storing data. Many databases are organized like ...
Pickling A limitation of dbm is that the keys and values have to be strings or bytes. If you try to use any ...
«
8
9
10
11
12
13
14
15
16
17
»
Free download pdf