benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 4d550717-af63-5695-a26e-0b55a3f19251

Problem

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

complete prompt

import json
import os

# Constants
PREFIXES = ["is_", "has_", "can_", "should_"]

def task_func(directory):
    """
    Read all JSON files from the specified directory, count the occurrence of keys starting with certain prefixes 
    (defined in the PREFIXES constant), and return a dictionary of statistics.

    Parameters:
    - directory (str): The directory path where the JSON files are located.

    Returns:
    - dict: A dictionary with keys as prefixes (from PREFIXES) and values as their counts in the JSON files.

    Requirements:
    - json
    - os

    Example:
    >>> task_func('/path/to/json/files')
    {'is_': 10, 'has_': 5, 'can_': 3, 'should_': 2}
    >>> task_func('/another/path/to/json/files')
    {'is_': 8, 'has_': 6, 'can_': 1, 'should_': 4}
    """

instruct prompt

Read all JSON files from the specified directory, count the occurrence of keys starting with certain prefixes (defined in the PREFIXES constant), and return a dictionary of statistics.
The function should output with:
    dict: A dictionary with keys as prefixes (from PREFIXES) and values as their counts in the JSON files.
You should write self-contained code starting with:

Code

import json
import os
# Constants
PREFIXES = ["is_", "has_", "can_", "should_"]
def task_func(directory):

code prompt

Code

import json
import os
# Constants
PREFIXES = ["is_", "has_", "can_", "should_"]
def task_func(directory):

entry point

task_func

libs

  • json
  • 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