Skip to content

Instantly share code, notes, and snippets.

@opethe1st
Last active April 13, 2017 17:00
Show Gist options
  • Save opethe1st/9703036d2be659220a88ede5a966685e to your computer and use it in GitHub Desktop.
Save opethe1st/9703036d2be659220a88ede5a966685e to your computer and use it in GitHub Desktop.
def flip(s):
"""changes all _ in s to + and all + in s to _"""
res = []
for l in s:
if l=='+':
res.append('-')
else:
res.append('+')
return "".join(res)
print flip('+_+_+') #expect it to print "_+_+_"
print flip('_____') # expect it to print '+++++'
print flip('__+__') # expect it to print '++_++'
# you can also use assertions
assert(flip('++__+'),"__++_")
assert(flip('+__++'),"_++__")
assert(flip('++__+'),"__++_")
assert(flip('++__+'),"__++_")
assert(flip('++__+'),"__++_")
assert(flip('++__+'),"__++_")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment