Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals. Explore comprehensive solutions to your questions from a wide range of professionals on our user-friendly platform.

Write a function called count_types that returns a dictionary with keys that are Pokemon types and values that are the number of times that type appears in the dataset. The order of the keys in the returned dictionary does not matter. In terms of efficiency, your solution should NOT iterate over the whole dataset once for each type of Pokemon since that would be overly inefficient. For example, assuming we have parsed pokemon_test.csv and stored it in a variable called data:

Sagot :

Answer:

Explanation:

The following code is written in Python. It creates a function called count_types which takes in three parameters. The pokemon in question, the data set, and a dictionary with all the pokemon types and values (Empty to start). Then it simply uses the built-in Python count feature to count the number of times that the Pokemon appears in the data set. Finally it saves that pokemon as a key and count as a value to the dictionary.

def count_types(pokemon, data, my_dict):

   count = data.count(pokemon)

   my_dict += {pokemon: count}