Created
June 1, 2012 14:39
-
-
Save sauravtom/2852596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_it(x,y,z): | |
# To Do : for x in z: replace x by y,again and again | |
# 1st step: if x appears in z | |
# 2nd step: then replce x by y | |
for i in range(len(z)-3): | |
if z[i:i+3]==x: # I cannot understand why this is not working , I set | |
z=z[:i]+y+z[i+3:] # the condition that if x is in z then modify z as follows | |
i=0 # and then I set i as 0 , and go over the loop again, | |
# find another instance where x is in z and do all of it again, but apparently this | |
# isn't working ,it should return just 'ab' , but it returns 'aaaaabaaaaa' What am I . # doing wrong here? | |
return z | |
print do_it('aba','b','aaaaaabaaaaaa') | |
# >>> ab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment