• Register
1 vote
39 views

Problem:

Hello

I am starting my programming experience with python recently. I’ve been surfing over the internet for a program that can remove punctuation from a String. I’ve found many of them but still can’t understand them. I am looking for a program written in very basic codes. If possible, please write me a program which would be easy to understand for me.

Thanks

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:
Hello Gavin.

I hope you are doing great today.  It’s nice to someone asked a question in a polite way and briefly.

I’ve snippet a program below and tried to make it as simple as possible for your better understanding.

# define punctuation
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''

my_str = "Hello!!!, My name --- is Gavin."

# To take input from the user
# my_str = input("Enter a string: ")

# remove punctuation from the string
no_punct = ""
for char in my_str:
   if char not in punctuations:
       no_punct = no_punct + char

# display the unpunctuated string
print(no_punct)

This basic program will remove all the punctuations from a String. It will check each and every character of a string inside the for loop If it founds a punctuation an empty string will be assigned to it.

In this way, every punction will be removed from our string.

Thanks

 

13 9 6
94,240 points

Related questions

1 vote
1 answer 80 views
80 views
Problem: I was trying to remove a letter from a string by writing this python program: def removechar(p, q) : counts = p.count(q) p = list(p) while counts : p.remove(q) counts -= 1 print(p) if __name__ == '__main__' : p = "nooneisallinall" removechar(p,'n') And the program ... 'l', 'l', 'i', 'a', 'l', 'l'] How can I get the output as string after removing the specific letter. Thanks in advance.
asked May 16, 2020 samhaz 5k points
0 votes
1 answer 9 views
9 views
I want to know how to remove all punctuation from a string in python
asked Sep 25, 2020 Daniel Anderson 4k points
1 vote
1 answer 22 views
22 views
Problem: I am beginner in pyhton programing. I have a dictionary of string and int and that is: Dictionary = { "Hola": 65, "tart" : 32, "star" : 34, "site" : 55, "pearl" : 88 } Supose I have to remove a key from this dictionary what should I do next.
asked Mar 28, 2020 LizzyM 6.1k points
1 vote
1 answer 20 views
20 views
Problem: I was tring to find the length of a string in python. So I wrote a code: string = 0 for c in "popular": string+==1 print (string) which gives following error; File "ab.py", line 3 string+==1 ^ SyntaxError: invalid syntax Is this the right way to do this or there are other waysto find this out?
asked Mar 28, 2020 LizzyM 6.1k points
1 vote
1 answer 29 views
29 views
Problem: I am beginner in pyhton prgramming language, I tried to convert string array to int array using python so I wrote a code which contains- testing_list = ['4', '2', '3', '9', '5'] And my code is: testing_list = ['4', '2', '3', '9', '5 ... list is : str(testing_list) Converted list is : str(testing_list) why am I not getting the converted result and what is the way to get the acurate result?
asked Mar 29, 2020 LizzyM 6.1k points
0 votes
1 answer 22 views
22 views
I am new to python programming I was trying to check if a letter is uppercase in python. I wrote some code to check this statement : import string def UpperCase(s_str): for x in s_str: if x not in string.UpeerCase: return False return True But I can not get the actual ... last): File "<stdin>", line 1, in <module> NameError: name 'LoWWE' is not defined Can anyone help me to solve this thing?
asked Mar 14, 2020 LizzyM 6.1k points
0 votes
1 answer 13 views
13 views
I require to remove all the special characters, puntuation and and speces from a string?
asked Sep 14, 2020 Daniel Anderson 4k points
1 vote
1 answer 20 views
20 views
Problem: Hello Kodlogs, I am a new student in Python programming. I was trying to do some business with Python string. Already learned some operations regarding strings. I was wondering if I can remove a particular character from a line. Therefore I tried the below script: ... a faster and efficient way. Could you please share an idea to do that? I must recognize your kind help. Thanks in advance.
asked Jul 1, 2020 adamSw 11.3k points
1 vote
1 answer 54 views
54 views
Problem: Hello all, I am a newbie in C++ programming. I took up this project of learning with a big dream in my head. Anyway, I am struggling with a problem to figure out the solution. I was finding some basic problems from some websites to solve them. Sudden;y, I ... I explained it all to you. Now, could you please solve the problem for me? I am waiting for your answer. Thanks for your kind help.
asked May 19, 2020 adamSw 11.3k points
1 vote
1 answer 520 views
520 views
Problem: I am getting the following error : error: array initializer must be an initializer list or string literal For the array; char x[80] = GetString(); Can any body explain or help?
asked Apr 2, 2020 LizzyM 6.1k points