Functional Python Programming
Working with Collections We can use this function as follows: def lat_lon_kml(row_iter): return (pick_lat_lon(*row) for row in r ...
Chapter 4 We've explicitly separated low-level XML parsing from higher-level reorganization of the data. The XML parsing produce ...
Working with Collections We achieve better reuse by separating this simple pairing function. This, in the long run, is one of ou ...
Chapter 4 Our strategy for performing tail-call optimization is to replace the recursion with a generator expression. We can cle ...
Working with Collections The following are three examples to clarify the use of the next() and iter() functions: list(legs(x ...
Chapter 4 Adding a filter extension to this design might look something like the following code snippet: def legs_filter(lat_lon ...
Working with Collections The evaluation of the tuple() method actually leads to a proper object being built so that we can print ...
Chapter 4 We'll need to create a pipeline of simpler transformation functions. Above, we arrived at flt= ((float(lat), float(lon ...
Working with Collections a = sin(Δ_lat/2)2 + cos(lat_1)cos(lat_2)sin(Δ_lon/2)2 c = 2*asin(sqrt(a)) return R * c This is a relati ...
Chapter 4 The problem we'll have using Python is that the output generator in the trip variable can only be used once. We can't ...
Working with Collections In Python, we can switch the order of the terms and transcribe these to working code as follows: not al ...
Chapter 4 We can demonstrate that Python follows these rules: all(()) True any(()) False Python gives us some very nice to ...
Working with Collections Using sums and counts for statistics The definitions of the arithmetic mean have an appealingly trivial ...
Chapter 4 We can use this scalar function as follows: d = [2, 4, 4, 4, 5, 5, 7, 9] list(z(x, mean(d), stdev(d)) for x in d) [ ...
Working with Collections This correlation function gathers basic statistical summaries of the two sets of samples: the mean and ...
Chapter 4 The following is an example that shows what the zip() function does: xi= [1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63, ...
Working with Collections Finally, we'll look at the different-length list approach used by the zip() function: list(zip((1, 2 ...
Chapter 4 We can easily use ((line.split() for line in file) to create a sequence of ten tuples. We might heave data in blocks t ...
Working with Collections We can write nested generator functions to build a sequence-of-sequence structure from flat data. In or ...
Chapter 4 This isn't as delightfully simple and functional-looking as other algorithms we've looked at. We can rework this into ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf