Basic string error in python -


Question: Write a function called sensor that takes two strings, text and words as input. Def sensor (text, word): t = text w = word l2 = len (word) res = "" p = ["*" * l2] str1 = "" . For the category I (p) (0, lane (text)): If the t [i] is in the text and not in the t [i] word: (= "hey hey", "hey") for input Res = res + t [i] + str1 return leakage

; The correct result is three three groups *** each. My code only gives two groups of three stars. Any ideas why?

Very easy partition and either replace "*" * or Just to keep the word:

  def sensor (text, word): l2 = len (word) p = "*" * l2 return "" .join ([ch if ch! = Text The word for ch in .plit ("")] is the word else p  

str1 = "". Join (p) > P = "*" * l2

if you use str.replace in other answers in partial matches it can be changed heys -> s *** / code>

In addition, we To explicitly divide the delimiter, when we reconnect, we will retain the length of the original string.

If you want to sort the first punctuation string import punctuation def sensor (text , Word) to rstrip :

 use : l2 = len (word) p = "*" * l2 return "". [3]: sensor ( "Foo! Fobar", "foo") in [3] in [ch] (text) for text.plit ("")] in C. : '*** Fobar'  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -