Last active
April 13, 2017 17:00
-
-
Save opethe1st/9703036d2be659220a88ede5a966685e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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