I think it is not the complete asnwer

Hi.

As per the description below.

asnwer

For the answer to be complete I think it would require:

asnwer02

Without the [0][0] you won’t get the key but the pair (key,value).

Perhaps it is a matter of interpretation. Please, share your thoughts.

2 Likes

Please make sure that when you ask questions -

  1. Share the link to the Mission/Mission Step
  2. Try to apply the appropriate tags to the question if possible

Otherwise, there is limited context to your questions for someone from the community to be able to help you out.

You can also refer to Introducing guidelines for all technical questions in our Community and Guide: How to Ask a Good Question as well.

1 Like

Here is the link for the mentioned matter.

https://app.dataquest.io/m/307/the-mode/3/the-mode-for-nominal-variables

Regards.
Italo Santos.

max function returns key of maximum element not key value pair.

Consider this simple example

>>> d = {'a':5, 'b':2,'c':10,'d':3}
>>> max(d, key=d.get)
'c'

PS: Can you show us if you are getting other output?

There are couple of things to note here -

As Dishin pointed out above, the following -

return max(counts, key = counts.get)

returns the key corresponding to the highest value in the dictionary.

Secondly, the code that you show, you are calling a function called ModeFunc and not the function mode.

So, there’s no indication of what you’ve implemented in the ModeFunc() function. Based on your implementation, you could require adding additional indexing to get the right answer. It depends on your implementation.

1 Like

Sorry people, that was a typo, I wrote one solution that’s is different than Dataquest’s, I copied and pasted my function name twice and I hadn’t noticed that. Attached my jupyter notebook just to explain my mistake.Get.ipynb (2.1 KB)

Click here to view the jupyter notebook file in a new tab

1 Like