[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
of a dictionary whose values are all None. Because lookup time is constant and short for dictionaries, the in list scans of the ...
This works about the same as the previous version, even though the internal imple- mentation is radically different: >>> ...
>>> x = fastset.Set([(1, 2), (3, 4)]) >>> x & fastset.Set([(3, 4), (1, 5)]) <Set:[(3, 4)]> Timing th ...
These results will vary per machine, and they may vary per Python release. But at least for this specific test case, the diction ...
Project Extract named fields from the tuples in a table. Difference Remove one set’s tuples from another. These operations go be ...
def intersect(self, other): # other is any sequence type res = [] # self is the instance subject for x in self: if x in other: r ...
not address data structures of radically different form—like those of the next two sections. Binary Search Trees Binary trees ar ...
{1, 3, 9} >>> set(v) # set constructor {1, 3, 9} >>> {k: k+100 for k in v} # dict comprehension {1: 101, 3: 10 ...
class EmptyNode: def repr(self): return '*' def lookup(self, value): # fail at the bottom return False def insert(self, value): ...
( *, 3, * ) ( ( *, 1, * ), 3, * ) ( ( *, 1, * ), 3, ( *, 9, * ) ) ( ( *, 1, ( *, 2, * ) ), 3, ( *, 9, * ) ) ( ( *, 1, ( *, 2, * ...
class EmptyNode: def repr(self): return '*' def lookup(self, key): # fail at the bottom return None def insert(self, key, val): ...
evolution, more robustly. To see a data structure that departs even further from the built-in gang, though, we need to move on t ...
with a list of keys of nodes it leads to (i.e., its arcs). This file also defines a function that we’ll use to run a few searche ...
Example 18-18. PP4E\Dstruct\Classics\gsearch2.py "graph search, using paths stack instead of recursion" def search(start, goal, ...
how and when extensions are added to its path’s stack; try tracing through the outputs and code to see how. Moving Graphs to Cla ...
constructed strings to do the work of seven assignment statements (A=Graph('A'), B=Graph('B'), and so on). Example 18-20. PP4E\D ...
This test finds three paths in its graph between nodes S and M. We’ve really only scratched the surface of this academic yet use ...
for i in range(len(list)): pick = list[i:i+1] # sequence slice rest = list[:i] + list[i+1:] # keep [:i] part for x in subset(res ...
[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)] >>> for i in range(0, 6): print(i, combo("help", i)) ... 0 [''] 1 ['h', 'e ...
Implementing Reversals Reversal of collections can be coded either recursively or iteratively in Python, and as functions or cla ...
«
67
68
69
70
71
72
73
74
75
76
»
Free download pdf