benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 0eb10903-ad5d-53d0-9dea-16ab419f62b5

Problem

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

complete prompt

import collections
import json
import os


def task_func(directory_path: str) -> dict:
    """
    Count the total appearances of all keys in all JSON files in the specified directory and return a dictionary 
    with the keys from the JSON files as keys and their respective counts as values.

    Parameters:
    - directory_path (str): The path to the directory containing the JSON files.

    Returns:
    dict: A dictionary with the keys from the JSON files as keys and their counts as values.

    Requirements:
    - collections
    - json
    - os

    Examples:
    >>> import tempfile
    >>> import json
    >>> directory = tempfile.mkdtemp()
    >>> data = [{'name': 'John', 'age': 25, 'address': '123 Main St'}, {'name': 'Doe', 'age': 30}, {'name': 'Jane', 'age': 35}]
    >>> for i, d in enumerate(data):
    ...     with open(f"{directory}/sample_{i}.json", 'w') as file:
    ...         json.dump(d, file)
    >>> task_func(directory)
    {'name': 3, 'age': 3, 'address': 1}
    """

instruct prompt

Count the total appearances of all keys in all JSON files in the specified directory and return a dictionary with the keys from the JSON files as keys and their respective counts as values.
The function should output with:
    dict: A dictionary with the keys from the JSON files as keys and their counts as values.
You should write self-contained code starting with:

Code

import collections
import json
import os
def task_func(directory_path: str) -> dict:

code prompt

Code

import collections
import json
import os
def task_func(directory_path: str) -> dict:

entry point

task_func

libs

  • json
  • collections
  • os

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