Returns a list of paths which go from the provided pages to either the source or target pages. Args: page_ids: The list of page IDs whose paths to get. Returns: list(list(int)): A list of lists of page IDs corresponding to paths from the provided page IDs to the source or target
(page_ids, visited_dict)
| 5 | |
| 6 | |
| 7 | def get_paths(page_ids, visited_dict): |
| 8 | """Returns a list of paths which go from the provided pages to either the source or target pages. |
| 9 | |
| 10 | Args: |
| 11 | page_ids: The list of page IDs whose paths to get. |
| 12 | |
| 13 | Returns: |
| 14 | list(list(int)): A list of lists of page IDs corresponding to paths from the provided page IDs |
| 15 | to the source or target pages. |
| 16 | """ |
| 17 | paths = [] |
| 18 | |
| 19 | for page_id in page_ids: |
| 20 | if page_id is None: |
| 21 | # If the current page ID is None, it is either the source or target page, so return an empty |
| 22 | # path. |
| 23 | return [[]] |
| 24 | else: |
| 25 | # Otherwise, recursively get the paths for the current page's children and append them to |
| 26 | # paths. |
| 27 | current_paths = get_paths(visited_dict[page_id], visited_dict) |
| 28 | for current_path in current_paths: |
| 29 | new_path = list(current_path) |
| 30 | new_path.append(page_id) |
| 31 | paths.append(new_path) |
| 32 | |
| 33 | return paths |
| 34 | |
| 35 | |
| 36 | def breadth_first_search(source_page_id, target_page_id, database): |
no outgoing calls
no test coverage detected