benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf d55d8253-a664-5fe1-a2b1-0d7edce85c93

Problem

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

complete prompt

from collections import Counter
import numpy as np
import matplotlib.pyplot as plt
import itertools

def task_func(list_of_menuitems, title="Menu Distribution", color="blue", width=1.0):
    """
    Given a nested list of menu items, flatten the list using itertool chain, count the occurrences of each item, then
    plot a histogram with an alphabetically sorted x-axis labeled as "Menu Items" and y-axis as "Frequency".

    Parameters:
    - list_of_menuitems (list): A non-empty nested list of menu items. Each element is a list of menu item strings.
    - title (str, optional): The title of the histogram plot. Default is "Menu Distribution".
    - color (str, optional): The color of the bars in the histogram. Default is "blue".
    - width (float, optional): The width of the bars in the histogram. Default is 1.0.

    Returns:
    - ax (object): An Axes object representing the histogram plot.

    Requirements:
    - collections.Counter
    - numpy
    - matplotlib.pyplot
    - itertools

    Example:
    >>> task_func([['Pizza', 'Burger'], ['Pizza', 'Coke'], ['Pasta', 'Coke']])
    <Axes: title={'center': 'Menu Distribution'}, xlabel='Menu Items', ylabel='Frequency'>
    >>> task_func(['Burger'], title='A Title', color='red', width=5.0)
    <Axes: title={'center': 'A Title'}, xlabel='Menu Items', ylabel='Frequency'>
    """

instruct prompt

Given a nested list of menu items, flatten the list using itertool chain, count the occurrences of each item, then plot a histogram with an alphabetically sorted x-axis labeled as "Menu Items" and y-axis as "Frequency".
The function should output with:
    ax (object): An Axes object representing the histogram plot.
You should write self-contained code starting with:

Code

from collections import Counter
import numpy as np
import matplotlib.pyplot as plt
import itertools
def task_func(list_of_menuitems, title="Menu Distribution", color="blue", width=1.0):

code prompt

Code

from collections import Counter
import numpy as np
import matplotlib.pyplot as plt
import itertools
def task_func(list_of_menuitems, title="Menu Distribution", color="blue", width=1.0):

entry point

task_func

libs

  • matplotlib
  • collections
  • numpy
  • 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