benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 8e603c0a-b7c6-57e3-8836-926fb1274a78

Problem

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

complete prompt

from collections import Counter
from random import choice, seed

# Constants
POSSIBLE_ITEMS = ['apple', 'banana', 'cherry', 'date', 'elderberry']

def task_func(list_of_lists):
    """
    Create a "shopping cart" (Counter object) for each list in list_of_lists. 
    The items in the cart are randomly selected from a predefined list of possible items (POSSIBLE_ITEMS).
    The frequency of each item in the cart corresponds to the length of the list.

    Parameters:
    - list_of_lists (list): A list of lists, each representing a 'basket'.

    Returns:
    - baskets (list): A list of Counters, each representing a 'shopping cart'.

    Requirements:
    - collections
    - random

    Example:
    >>> baskets = task_func([[1, 2, 3], [4, 5]])
    >>> all(isinstance(basket, Counter) for basket in baskets) # Illustrative, actual items will vary due to randomness
    True
    >>> sum(len(basket) for basket in baskets) # The sum of lengths of all baskets; illustrative example
    3
    """

instruct prompt

Create a "shopping cart" (Counter object) for each list in list_of_lists. The items in the cart are randomly selected from a predefined list of possible items (POSSIBLE_ITEMS). The frequency of each item in the cart corresponds to the length of the list.
The function should output with:
    baskets (list): A list of Counters, each representing a 'shopping cart'.
You should write self-contained code starting with:

Code

from collections import Counter
from random import choice, seed
# Constants
POSSIBLE_ITEMS = ['apple', 'banana', 'cherry', 'date', 'elderberry']
def task_func(list_of_lists):

code prompt

Code

from collections import Counter
from random import choice, seed
# Constants
POSSIBLE_ITEMS = ['apple', 'banana', 'cherry', 'date', 'elderberry']
def task_func(list_of_lists):

entry point

task_func

libs

  • collections
  • random

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