python - Replacing a letter with a word -


I'm thinking that to write a function that uses a word with a word without using any function functions Changes. For example, eyeForI ("William") returns "Weyleleyeam" which changes i with eyes.

I know how to do this with a built-in function which I have written something like this before (though in this case it changes a word with a different word): < / P>

  def stringChange ("no", "should not be"), ("no", "no"), (old), in new (("can not", "no "), (" Will not "," will not be "),): s = s.replace (old, new) if"! " S: s = s.upper () Returns S  

But I do not know how to write it without using any built functions.

I know that I have to use for the loop.

Here you try and separate for something rather than loop, generator, dictionary in it Contains the default argument for get , and join . You can repeat through a string, which means that you do not need to convert it to the first list.

  s1 = "William" subs = {'I': 'eye'} s2 = '' .join (subs.get (c, c) ) For s1) print (s2)  

This is a solution that does not call anything that would be properly called a function or method, although it is not very "phenol" Due to the hard-coding condition it will be difficult to expand, and repeated strings will not be liked.

  def nephori (word): result = "# # create empty string so that we can add it to c in the word: #c will be set to each character if C == 'I': Results + = 'Eyes' # Add words to the end of the results: result + = C # result return letter add letter at the end of the result eyeForI ("William") == "wildleme" # test this works  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -