benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 9586d57a-fe49-5b43-8806-a80dd61bdfec

Problem

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

complete prompt

import numpy as np
from collections import Counter


def task_func(list_of_tuples):
    """
    Computes the sum of numeric values and counts the occurrences of categories in a list of tuples.

    Each tuple in the input list contains a numeric value and a category. This function calculates
    the sum of all the numeric values and also counts how many times each category appears in the list.

    Parameters:
    - list_of_tuples (list of tuple): A list where each tuple contains a numeric value and a category.

    Returns:
    - tuple: A 2-element tuple where the first element is the sum of the numeric values, and the
             second element is a dictionary with categories as keys and their counts as values.

    Requirements:
    - numpy
    - collections.Counter

    Example:
    >>> list_of_tuples = [(5, 'Fruits'), (9, 'Vegetables'), (-1, 'Dairy'), (-2, 'Bakery'), (4, 'Meat')]
    >>> sum_of_values, category_counts = task_func(list_of_tuples)
    >>> print(sum_of_values)
    15
    >>> print(category_counts)
    {'Fruits': 1, 'Vegetables': 1, 'Dairy': 1, 'Bakery': 1, 'Meat': 1}
    """

instruct prompt

Computes the sum of numeric values and counts the occurrences of categories in a list of tuples. Each tuple in the input list contains a numeric value and a category. This function calculates the sum of all the numeric values and also counts how many times each category appears in the list.
The function should output with:
    tuple: A 2-element tuple where the first element is the sum of the numeric values, and the
    second element is a dictionary with categories as keys and their counts as values.
You should write self-contained code starting with:

Code

import numpy as np
from collections import Counter
def task_func(list_of_tuples):

code prompt

Code

import numpy as np
from collections import Counter
def task_func(list_of_tuples):

entry point

task_func

libs

  • collections
  • numpy

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