[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
else: return reverse(list[1:]) + list[:1] # add front item on the end def ireverse(list): res = list[:0] # empty, of same type f ...
Here is this module’s self-test code in action; the first tests sort dictionaries, and the last sort tuples: C:\...\PP4E\Dstruct ...
Although these examples serve an educational role, built-in lists and functions generally accomplish what we just did the hard w ...
off not reinventing the data structure wheel unless you have to. Built-in functionality will often prove a better choice in the ...
The GUI interfaces PyTree utilizes were covered in depth earlier in this book. Because it is written with Python and tkinter, it ...
Just like the PyForm example of the preceding chapter, the source code and documen- tation for this example have been moved to t ...
CHAPTER 19 Text and Language “See Jack Hack. Hack, Jack, Hack” In one form or another, processing text-based information is one ...
Parsers: markup XML and HTML text parsing Parsers: grammars Custom language parsers, both handcoded and generated Embedding Runn ...
'spam = "ham ", +00099' >>> 'spam = "{0:<5}", {1:+06}'.format('ham', 99) 'spam = "ham ", +00099' These operations ar ...
Moreover, in Python today all normal string methods apply to both bytes and str strings. The latter makes them applicable to arb ...
>>> import string >>> template = string.Template('---$key1---$key2---') >>> template.substitute(vals) ...
Summing Columns in a File Let’s look next at some practical applications of string splits and joins. In many do- mains, scanning ...
3 len('abc') [1,2,3][2] {'spam':3}['spam'] C:\...\PP4E\Lang> python summer.py 4 table2.txt [21, 21, 21, 21.0] Summing with zi ...
C:\...\PP4E\Lang> python >>> print(open('table4.txt').read()) 001.1 002.2 003.3 010.1 020.2 030.3 040.4 100.1 200.2 ...
Tests and conclusions are conjunctions of terms (“,” means “and”). Each term is a list of words or variables separated by spaces ...
def external(conjunct): return ', '.join(' '.join(clause) for clause in conjunct) to produce the desired nested lists and string ...
field to explore, but holmes is probably best left to the foggy mists of Python prehistory (and souls brave enough to try the po ...
Regular expressions are simply strings that define patterns to be matched against other strings. Supply a pattern and a string a ...
To demonstrate, let’s do some matching on the following strings (see file re-interactive.txt for all the interactive code run in ...
in the middle ((.*)), and allows the final word to begin with an upper- or lowercase letter ([Ww]); as you can see, patterns can ...
«
68
69
70
71
72
73
74
75
76
77
»
Free download pdf