On 11/19/2011 04:59 PM, Dave Angel wrote:
On 11/19/2011 01:36 AM, Kĩnũthia Mũchane wrote:
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 ==
On 11/19/2011 01:36 AM, Kĩnũthia Mũchane wrote:
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]
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:]
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(myl
On 11/18/2011 06:04 PM, Dave Angel wrote:
On 11/18/2011 08:16 AM, Kĩnũthia Mũchane wrote:
Well, it doesn't count the number of occurrences correctly if the list
is empty. It should get zero, and it gets -1. But for any non-empty
list, nothing ever looks at the -1 value, so it doesn't matte
On 11/18/2011 08:16 AM, Kĩnũthia Mũchane wrote:
Hi,
I am trying to do something which is really stupid :-)
I would like to count the number of occurrences of a certain character
in a list.
This is more of an exercise in recursion rather than the underlying
problem.
I could have used a *for* l
On 2011/11/18 03:16 PM, Kĩnũthia Mũchane wrote:
Hi,
I am trying to do something which is really stupid :-)
I would like to count the number of occurrences of a certain character
in a list.
This is more of an exercise in recursion rather than the underlying
problem.
I could have used a *for* l
Hi,
I am trying to do something which is really stupid :-)
I would like to count the number of occurrences of a certain character
in a list.
This is more of an exercise in recursion rather than the underlying problem.
I could have used a *for* loop or simply the list *count* method.
Here is the