Question
[Python] I need help with counting punctuation in a file in python. I have the following function: def remove_punc(s): result = for c in
[Python] I need help with counting punctuation in a file in python. I have the following function:
def remove_punc(s): result = "" for c in s: # If char is not punctuation, add it to the result. if c not in string.punctuation: result += c return result
#########################
and I have called it from main like this:
def main(): myFile = open("gameofthrones.txt", "r") punctCount = 0 for line in myFile: print(remove_punc(line))
myFile.close()
if __name__ == '__main__': main()
##############################################
But now I have to count the amount of punctuation in the file, and I am not sure how to do that using the punctCount counter, any help is appreciated.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started