Khan Academy now has a series of videos on Python programming [EDIT: they have since been removed], and I've spent way too much of this weekend watching them, despite knowing all the basics of Python (I did learn a couple of things though).

In fact, I spent so much time watching videos, I finally broke the million point mark (and now have 77 points in binary):

Khan energy points crop

Anyway, that's by-the-by and just showing off. The main point was that in one video Sal sets an exercise to create a function to return the nth Fibonacci number. The idea was to write a function either using recursion or a for loop, but having learnt a bit about Python iterators and functional programming, I wondered if there was a fancier way to do it, using something like the reduce() function.

This is what I came up, but it's not it's not very pretty. I'm sure there must be a better way that doesn't require a generator of tuples, which doesn't do much for the most part.

def fibonacci(n):
  if n > 0:
    a = ((0,1) for _ in range(n))
    return reduce(
      lambda x, y: (x[1], x[0]+x[1]),
      a
    )[1]
  else:
    return 0