fork(2) download
  1. f=lambda x:x and[sum(x[:x[0]])]+f(x[1:])
  2.  
  3. for x in [3, 2, 4, 1, 1, 5, 1, 2], [1, 2, 3, 4, 5], [3, 3, 3, 3, 3, 3, 3, 3], [5, 1, 2, 4, 1], [1]:
  4. print '%-24s -> %s' % (x, f(x))
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
[3, 2, 4, 1, 1, 5, 1, 2] -> [9, 6, 11, 1, 1, 8, 1, 2]
[1, 2, 3, 4, 5]          -> [1, 5, 12, 9, 5]
[3, 3, 3, 3, 3, 3, 3, 3] -> [9, 9, 9, 9, 9, 9, 6, 3]
[5, 1, 2, 4, 1]          -> [13, 1, 6, 5, 1]
[1]                      -> [1]