benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 80c4e191-59ba-54e3-b718-d3cee7c9d231

Problem

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

complete prompt

import collections
import matplotlib.pyplot as plt


def task_func(data):
    """
    Combine a list of dictionaries with the same keys (fruit names) into a single dictionary,
    calculate the total turnover for each fruit, and return a bar chart's axes with colors representing
    different fruits. The colors are selected from: 'red', 'yellow', 'green', 'blue', 'purple'. The function
    ensures that sales quantity must not be negative, throwing a ValueError if encountered.

    Parameters:
    data (list): A list of dictionaries. The keys are fruit names and the values are sales quantities.
                 Sales quantity must not be negative.

    Returns:
    total_sales (dict): A dictionary containing the total sales for each fruit.
    ax (matplotlib.container.BarContainer): A bar chart of total fruit sales, or None if data is empty

    Requirements:
    - collections
    - matplotlib.pyplot

    Example:
    >>> sales, plot = task_func([{'apple': 10, 'banana': 15, 'cherry': 12},\
                             {'apple': 12, 'banana': 20, 'cherry': 14},\
                             {'apple': 15, 'banana': 18, 'cherry': 15},\
                             {'apple': 11, 'banana': 17, 'cherry': 13}])
    >>> sales
    {'apple': 48, 'banana': 70, 'cherry': 54}
    >>> type(plot)
    <class 'matplotlib.container.BarContainer'>
    """

instruct prompt

Combine a list of dictionaries with the same keys (fruit names) into a single dictionary, calculate the total turnover for each fruit, and return a bar chart's axes with colors representing different fruits. The colors are selected from: 'red', 'yellow', 'green', 'blue', 'purple'. The function ensures that sales quantity must not be negative, throwing a ValueError if encountered.
The function should output with:
    total_sales (dict): A dictionary containing the total sales for each fruit.
    ax (matplotlib.container.BarContainer): A bar chart of total fruit sales, or None if data is empty
You should write self-contained code starting with:

Code

import collections
import matplotlib.pyplot as plt
def task_func(data):

code prompt

Code

import collections
import matplotlib.pyplot as plt
def task_func(data):

entry point

task_func

libs

  • collections
  • matplotlib

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