Python Exercises: Replace a word with hash characters in a string
Replace long words with hash.
Write a Python program to replace each character of a word of length five and more with a hash character (#).
Sample Solution-1:
Python Code:
Sample Output:
Original string: Count the lowercase letters in the said list of words: Replace words (length five or more) with hash characters in the said string: ##### the ######### ####### in the said list of ###### Original string: Python - Remove punctuations from a string: Replace words (length five or more) with hash characters in the said string: ###### - ###### ############ from a #######
Flowchart:

Sample Solution-2:
Python Code:
Sample Output:
Original string: Count the lowercase letters in the said list of words: Replace words (length five or more) with hash characters in the said string: ##### the ######### ####### in the said list of ###### Original string: Python - Remove punctuations from a string: Replace words (length five or more) with hash characters in the said string: ###### - ###### ############ from a #######
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to replace every character of a word with '#' if the word’s length is five or more.
- Write a Python program to use regular expressions to substitute words with length ≥ 5 with a sequence of '#' characters of the same length.
- Write a Python program to iterate over words in a sentence and replace each long word with a hashed version while leaving shorter words unchanged.
- Write a Python program to implement a function that processes a sentence and returns a new string where words of length five or more are masked with '#'.
Python Code Editor:
Previous Python Exercise: Remove punctuations from a string.
Next Python Exercise: Capitalize the first letter and lowercases the rest.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics