Created
April 30, 2014 20:11
-
-
Save sente/b048105f7c1d6ed75a15 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 ari(s): | |
town = [] | |
s = [c for c in s] + [None] | |
for a,b in zip(s, s[1:]): | |
if a != b: | |
town.append(a) | |
return ''.join(town) | |
if __name__ == '__main__': | |
s = "foooooooooooo baaaaaaaaaaaaar" | |
print s | |
print ari(s) |
this was the solution that seemed most obvious, and which I'd do if it was a one-off in the repl, but zip
is just too cool so I did it that way
def ariobv(s):
town = [s[0]]
for c in s:
if c != town[-1]:
town.append(c)
return town
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My method looked something like this: