Skip to content

Instantly share code, notes, and snippets.

@hongruiqi
Created April 4, 2014 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hongruiqi/9978572 to your computer and use it in GitHub Desktop.
Save hongruiqi/9978572 to your computer and use it in GitHub Desktop.
def isSame(a, b):
return a==b
last = None
def f(sum, b):
global last
first = b[0]
if isSame(last, first):
sum[-1].extend(b[1:])
else:
sum.append(b)
last = first
return sum
print reduce(f, [["1", 1, 2], ["1", 3, 4], ["2", 5, 6], ["2", 7, 8], ["3", 1], ["4", 1]], [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment