benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf faeca27a-6c0e-594e-9df8-d475e7464856

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

from collections import Counter
from operator import itemgetter
import itertools

#CONSTANT
ANIMAL = ['cat', 'camel', 'cow', 'dog', 'elephant', 'fox', 'giraffe', 'hippo', 'iguana', 'jaguar']

def task_func(animal_dict):
    """
    Given a dictionary of animals as keys and letters as values, count the frequency of each letter in the animals.
    
    Note:
    - Remove key in the dictionary if it is not an animal from ANIMAL constant

    Parameters:
    animal_dict (dict): The dictionary with animals as keys and their letters as values.
    
    Returns:
    dict: A dictionary with letters as keys and their frequencies as values, sorted in descending order by frequency. Format: {letter: frequency}.
    
    Requirements:
    - collections.Counter
    - operator.itemgetter
    - itertools
    
    Example:
    >>> animal_dict = {'cat': 'c', 'dog': 'd', 'elephant': 'e', 'fox': 'f', 'giraffe': 'g', 'hippo': 'h', 'iguana': 'i', 'jaguar': 'j'}
    >>> counts = task_func(animal_dict)
    >>> print(counts)
    {'a': 7, 'g': 4, 'o': 3, 'e': 3, 'p': 3, 'f': 3, 'i': 3, 't': 2, 'h': 2, 'n': 2, 'r': 2, 'u': 2, 'c': 1, 'd': 1, 'l': 1, 'x': 1, 'j': 1}
    """

instruct prompt

Given a dictionary of animals as keys and letters as values, count the frequency of each letter in the animals.
Note that: Remove key in the dictionary if it is not an animal from ANIMAL constant
The function should output with:
    dict: A dictionary with letters as keys and their frequencies as values, sorted in descending order by frequency. Format: {letter: frequency}.
You should write self-contained code starting with:

Code

from collections import Counter
from operator import itemgetter
import itertools
#CONSTANT
ANIMAL = ['cat', 'camel', 'cow', 'dog', 'elephant', 'fox', 'giraffe', 'hippo', 'iguana', 'jaguar']
def task_func(animal_dict):

code prompt

Code

from collections import Counter
from operator import itemgetter
import itertools
#CONSTANT
ANIMAL = ['cat', 'camel', 'cow', 'dog', 'elephant', 'fox', 'giraffe', 'hippo', 'iguana', 'jaguar']
def task_func(animal_dict):

entry point

task_func

libs

  • operator
  • collections
  • itertools

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import