Advertisement
acclivity

pyProcessBookTitles

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