MCPcopy Index your code
hub / github.com/geekcomputers/Python / search_in_toc

Function search_in_toc

VoiceAssistant/Project_Basic_struct/textRead.py:293–320  ·  view source on GitHub ↗

Searches a particular lesson name provided as a parameter in toc and returns its starting and ending page numbers. Args: toc (nested list): toc[1] - Topic name toc[2] - Page number key (str): the key to be found totalpg (int): total pages

(toc, key, totalpg)

Source from the content-addressed store, hash-verified

291
292
293def search_in_toc(toc, key, totalpg):
294 """Searches a particular lesson name provided as a parameter in toc and returns its starting and ending page numbers.
295
296 Args:
297 toc (nested list): toc[1] - Topic name
298 toc[2] - Page number
299 key (str): the key to be found
300 totalpg (int): total pages in book/document
301
302 Returns:
303 int: staring and ending page numbers of lesson found.
304 If not found then return None
305 """
306 for i in range(len(toc) - 1):
307 topic = toc[i]
308 if i != len(toc) - 2:
309 if topic[1] == key:
310 nexttopic = toc[i + 1]
311 return (topic[2], nexttopic[2])
312 elif topic[1].lower() == key:
313 nexttopic = toc[i + 1]
314 return (topic[2], nexttopic[2])
315 else:
316 if topic[1] == key:
317 return (topic[2], totalpg)
318 elif topic[1].lower() == key:
319 return (topic[2], totalpg)
320 return None, None
321
322
323def book_details(author, title, total_pages):

Callers 1

pdf_readFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected