acclivity

pyBookTitlesRegex

Mar 10th, 2022 (edited)
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. textlist = ["Acts 1.txt", "1 Chronicles 1.txt", "2 Samuel 15.txt"]
  2.  
  3. for text in textlist:
  4.     mylist = re.split('([\s\.]+)', text)
  5.     if mylist[-1] == "txt":
  6.         mylist.pop(-1)
  7.     res = ""
  8.     digitctr = 0
  9.     for s in mylist:
  10.         if s.isdigit():                 # process a digit group
  11.             if res:
  12.                 digitctr += 1
  13.                 if digitctr == 1:           # 1st digit group after title is chapter
  14.                     res += "Chapter "
  15.                 elif digitctr == 2:         # 2nd digit group after title
  16.                     res += "Paragraph "        # ?????????
  17.             res += num2words(int(s))
  18.         elif s != '.':                           # a non-digit group
  19.             res += s
  20.  
  21.     print(res)
  22.  
  23. # output:-
  24. # Acts Chapter One
  25. # One Chronicles Chapter One
  26. # Two Samuel Chapter Fifteen
Add Comment
Please, Sign In to add comment