Skip to content

Instantly share code, notes, and snippets.

@sauravtom
Created June 1, 2012 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sauravtom/2852596 to your computer and use it in GitHub Desktop.
Save sauravtom/2852596 to your computer and use it in GitHub Desktop.
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