SHARE
TWEET

regex issue

a guest Aug 14th, 2019 87 in 6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2. grammer_words = "NOUN,PRONOUN,NUMBER,FEELING,ENDS-IN-ING,VERB".lower().split(",")
  3. madLib_file = open("madLib.txt","r")
  4. content = madLib_file.read().lower().split("\n")
  5. m = []
  6. for i in range(len(content)):
  7.     line = content[i].split(" ")
  8.     regex = re.compile(r"\b.-\s")
  9.     for word in line:
  10.         word = regex.search(word) #removes periods, commas and etc
  11.         if word: #word not a hiphen, comma, or etc
  12.             word = word.group()
  13.             try:
  14.                 matched = grammer_words.index(word) or "Noun"
  15.                 if matched:
  16.                     text = "Enter a "+matched+"."#ex: "Enter a verb"
  17.                     m.append(matched)
  18.             except:
  19.                 print("NO match")
  20.  
  21.  
  22. print(len(m))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top