f=lambda a:sum(int(`x`,y)for x,y in zip(a,[10]+a)) for test in ([4, 12, 34, 20, 14, 6, 25, 13, 33], [5, 14, 2, 11, 30, 18], [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 12, 2, 11, 3, 10, 2, 10], [36, 36]): print test, f(test)