1
def f(x):
    xs=str(x)
    if len(xs) == 1:
        return int(xs)
    n = int(xs[0]) + int (xs[1])
    if len (xs) == 2:
        return n
    else:
        return n+f(xs[2:])

Speciffically, what does f(xs[2:]) do?

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
Andra
  • 47
  • 1
  • 8
  • What are you asking? `xs[2:]` is slice notation as everybody said. If you ask about `return n+f(......)`, it is recursion. – Mp0int Dec 20 '13 at 15:05

1 Answers1

3

It is called slicing notation and it is creating a copy of the list excluding the first two items.

Community
  • 1
  • 1
thefourtheye
  • 233,700
  • 52
  • 457
  • 497