Replace four letter word in python

前端 未结 5 952
暗喜
暗喜 2020-12-12 08:24

I am trying to write a program that opens a text document and replaces all four letter words with **. I have been messing around with this program for multiple hour

5条回答
  •  醉梦人生
    2020-12-12 08:38

    Here is a hint: len(words) returns the number of words on the current line, not the length of any particular word. You need to add code that would look at every word on your line and decide whether it needs to be replaced.

    Also, if the file is more complicated than a simple list of words (for example, if it contains punctuation characters that need to be preserved), it might be worth using a regular expression to do the job.

提交回复
热议问题