Your task for this assignment is to write a simple program in Python 2.7 that wi
ID: 3792692 • Letter: Y
Question
Your task for this assignment is to write a simple program in Python 2.7 that will extract the words matching the certain patterns defined by the following regular expressions. All alphanumeric words with no symbols. (0...9^+ |A...Z^+ |a...z^+)^+ Example valid words: 'hotel', 'la Tech1928', '93894', 'zxvylk' All valid LaTech e-mail addresses. (a...z^+ |0... 1^+)^+@(a...z^+ |0... 1^+)^+.latech.edu Example valid words: '1234@latech.edu', 'narnia@latech.edu', 'robl@coes.latech.edu' All valid identifier names in C: (_|A...Z|a...z) (_|0... 9^+ |A...Z^+ |a... z^+)* Example valid words: '_a', 'constant_1', 'thisIS_my_variable' Write only one function that will extract words matching all three regular expressions. The following has been provided: An input file 'input_words.txt' containing random words. Instructions Pass an input file through a command-line. Import 're' library. Read one word at a time from an input file. Only spaces separate words. Write a function to check whether a word matches any of the defined regular expressions. All matching words must be written in a new line into an 'extracted_words.txt' file. Write comments to document your code appropriately.Explanation / Answer
outout:
Enter the input file name:input_words.txt
['worried', '_this', 'doing', 'emergencies', 'mulmi@latech.edu', 'for_more_info', '911', 'decide_1', 'or', 'This', 'is', 'call', 'very_interesting', 'program', 'can', 'even', 'some', 'contact', 'in_case_of', 'you', 'a']
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.