April 2018
Intermediate to advanced
408 pages
10h 42m
English
We'll look at two analysis functions that we can use to filter and analyze the individual AccessDetails objects. The first function, a filter() function, will pass only specific paths. The second function will summarize the occurrences of each distinct path.
We'll define a small book_in_path() function and combine this with the built-in filter() function to apply the function to the details. Here is the composite book_filter() function:
from typing import Iterable, Iteratordef book_filter( access_details_iter: Iterable[AccessDetails] ) -> Iterator[AccessDetails]: def book_in_path(detail: AccessDetails) -> bool: path = tuple( item for item in detail.url.path.split('/') if item ) return path[0] == 'book' and len(path) ...