Lesson 6
Dealing with Sequences of Objects
Chapter 8: Strings as a sequence
Replace string with blanks
One more short exercise!
Write a function blankify()
that takes a str
as an input argument, and returns a str
that replaces all occurrences of the first character of the string with the character "_"
.
For example, "my name is maria"
would become "_y na_e is _aria"
. The first letter is "m"
, so the function will return a new string with all the "m"
blanked out with an underscore.
For simplicity, assume that the function is case sensitive. That is, "My name is Maria"
will return "_y name is _aria"
, where the "m"
in "name"
is not replaced since it is not a capital "M"
.
Sample inputs and outputs
>>> blankify("easy peasy lemon squeezy")
'_asy p_asy l_mon squ__zy'
>>> blankify("Baby I was born this way")
'_aby I was born this way'
>>> blankify("baby I was born this way")
'_a_y I was _orn this way'
>>> blankify(" amazing grace how sweet the sound")
'_amazing_grace_how_sweet_the_sound'
>>> blankify("")
''