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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!