[Tutor] A recursion question
Kĩnũthia Mũchane
kinuthia.muchane at gmail.com
Sat Nov 19 07:36:02 CET 2011
On 11/19/2011 06:03 AM, Asokan Pichai wrote:
> Another way to do that is to avoid any intermediate variables altogether
> That may be easier to understand YMMV
>
> def counter(mylist, val):
> if len(mylist == 0):
> return 0
> if mylist[0] == val:
> return 1 + counter(mylist[1:], val)
> else:
> return counter(mylist[1:])
The intermediate variable explanation by Dave actually clinched it for
me. Actually, the one I wrote is suspiciously similar to yours ;-).
Anyway, thanks Asokan!
>
>
> Asokan Pichai
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
--
Kĩnũthia
S 1º 8' 24”
E 36º 57' 36”
1522m
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111119/1f613c48/attachment-0001.html>
More information about the Tutor
mailing list