Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That's a very much a 'pure functional' approach and as such is a sensible idiom in Haskell but it's probably not so appropriate to Python. Python only has a very limited concept of <a href="http://www.haskell.org/tutorial/patterns.html" rel="nofollow noreferrer">patterns</a> in this way - and I suspect you might need a somewhat more rigid type system to implement that sort of construct (<a href="http://www.erlang.org/" rel="nofollow noreferrer">erlang</a> buffs invited to disagree here).</p> <p>What you have is probably as close as you would get to that idiom, but you are probably better off using a list comprehension or imperative approach rather than recursively calling a function with the tail of the list. </p> <p>As has been <a href="http://www.oreillynet.com/onlamp/blog/2005/10/pythons_weak_functional_progra.html" rel="nofollow noreferrer">stated</a> <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=4550" rel="nofollow noreferrer">on a few occasions</a> <a href="http://blog.ianbicking.org/functional-python.html" rel="nofollow noreferrer">before</a>, Python is not actually a functional language. It just borrows ideas from the FP world. It is not inherently <a href="http://en.wikipedia.org/wiki/Tail_recursion" rel="nofollow noreferrer">Tail Recursive</a> in the way you would expect to see embedded in the architecture of a functional language, so you would have some difficulty doing this sort of recursive operation on a large data set without using a lot of stack space.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload