On 10/04/16 19:36, Peter Otten wrote:
> Alan Gauld wrote:
>
>> or a slightly sneaky but faster version:
>>
>> def howMany(aList):
>> return aList.index(aList[-1]) + 1
>
> Sorry, but this isn't "slightly sneaky", this is outright wrong.
> I fails for both empty lists and lists with duplicate e
Alan Gauld wrote:
> or a slightly sneaky but faster version:
>
> def howMany(aList):
> return aList.index(aList[-1]) + 1
Sorry, but this isn't "slightly sneaky", this is outright wrong.
I fails for both empty lists and lists with duplicate entries.
Hi Tom,
You can see what happens for yourself in the Pythontutor:
http://goo.gl/YVkh03 - step through the code by clicking on "Forward" and
see what happens. You are calling the howMany function from inside the
function itself, which is called recursion. This can be practical, but in
your case it
Hi,
I think your function runs forever because the only thing it done is
calling it self when entering the for loop
when you call your function in the for loop it jump to the definition (def
howMany(aDict)) then initialise count and bond the value 0 to it then enter
a for loop then call the funct
On 08/04/2016 21:48, Tom Maher wrote:
Hi,
As a test I am trying to write a function that returns the sum of values
attached to one key in a dictionary. I am wondering why the code that I
wrote is returning:
"maximum recursion depth exceeded"
Here is the code:
animals = { 'a': ['aardvark'], 'b':
On 09/04/16 00:34, Martin A. Brown wrote:
> You start by creating a dictionary that uses an initial letter as
> the key and a list to hold the names of the animals. Your function
> could probably be as simple as:
>
> def howMany(aList):
> return len(aList)
>
> Here is an inefficien
On 08/04/16 21:48, Tom Maher wrote:
> As a test I am trying to write a function that returns the sum of values
> attached to one key in a dictionary. I am wondering why the code that I
> wrote is returning:
> "maximum recursion depth exceeded "
Python has a limit to how many times you can recursi
Greetings Tom,
>As a test I am trying to write a function that returns the sum of
>values
Given the code you pasted, I think you mean 'count' of values,
right? I'll assume that below, because it is a tricky thing to sum
some strings.
>attached to one key in a dictionary. I am wondering why
On Fri, Apr 8, 2016 at 1:48 PM, Tom Maher wrote:
> Hi,
>
> As a test I am trying to write a function that returns the sum of values
> attached to one key in a dictionary.
Why does the program try to use recursion for this problem?
___
Tutor maillist -
Hi,
As a test I am trying to write a function that returns the sum of values
attached to one key in a dictionary. I am wondering why the code that I
wrote is returning:
"maximum recursion depth exceeded "
Here is the code:
animals = { 'a': ['aardvark'], 'b': ['baboon'], 'c': ['coati']}
x = anima
10 matches
Mail list logo