Skip to content

Instantly share code, notes, and snippets.

@sente
Created April 30, 2014 20:11
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 sente/b048105f7c1d6ed75a15 to your computer and use it in GitHub Desktop.
Save sente/b048105f7c1d6ed75a15 to your computer and use it in GitHub Desktop.
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)
@aripollak
Copy link

My method looked something like this:

def squash_adjacent_duplicate_chars(string)
  string.size.times.map do |i|
    string[i] unless string[i + 1] == string[i]
  end.flatten.join
end

@sente
Copy link
Author

sente commented Apr 30, 2014

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