benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 88ae172b-737a-5dcd-ad5c-fe714ed80fc7
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import random
import pandas as pd
import collections
# Constants
VEGETABLES = ['Carrot', 'Potato', 'Tomato', 'Cabbage', 'Spinach']
def task_func(vegetable_dict, seed=0):
"""
Calculate statistics for the vegetables preferred by people listed in the input dictionary.
The function reverses the dictionary to map vegetables to people and assigns random counts to these vegetables.
It then calculates the occurrences of each vegetable as a percentage of the total counts.
A dictionary is created to map each vegetable to a person from the input where vegetables are values.
Random counts between 1 and 10 are assigned to simulate varying popularity or availability of each vegetable.
Parameters:
vegetable_dict (dict): A dictionary mapping people's names to their preferred vegetables.
seed (int): An integer value to seed the random number generator. Defaults to 0.
Returns:
DataFrame: Returns a DataFrame with columns for vegetable names, their random counts,
and their percentage occurrence within the total counts.
Requirements:
- random
- pandas
- collections
Example:
>>> vegetable_dict = {'John': 'Carrot', 'Alice': 'Potato', 'Bob': 'Tomato'}
>>> print(task_func(vegetable_dict))
Count Percentage
Carrot 7 46.666667
Potato 7 46.666667
Tomato 1 6.666667
"""
instruct prompt
Calculate statistics for the vegetables preferred by people listed in the input dictionary. The function reverses the dictionary to map vegetables to people and assigns random counts to these vegetables. It then calculates the occurrences of each vegetable as a percentage of the total counts. A dictionary is created to map each vegetable to a person from the input where vegetables are values. Random counts between 1 and 10 are assigned to simulate varying popularity or availability of each vegetable.
The function should output with:
DataFrame: Returns a DataFrame with columns for vegetable names, their random counts,
and their percentage occurrence within the total counts.
You should write self-contained code starting with:
Code
import random
import pandas as pd
import collections
# Constants
VEGETABLES = ['Carrot', 'Potato', 'Tomato', 'Cabbage', 'Spinach']
def task_func(vegetable_dict, seed=0):
code prompt
Code
import random
import pandas as pd
import collections
# Constants
VEGETABLES = ['Carrot', 'Potato', 'Tomato', 'Cabbage', 'Spinach']
def task_func(vegetable_dict, seed=0):
entry point
task_func
libs
- pandas
- collections
- random
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
initial import