benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 2939345b-f52c-5e09-89a2-3b1eab2f8023

Problem

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

complete prompt

import json
import os
import glob


# Constants
KEY = 'mynewkey'
VALUE = 'mynewvalue'

def task_func(directory):
    """
    Add a new key-value pair to all JSON files in a specific directory and save the updated JSON files.
    
    Specifically, the function searches for all JSON files within the provided directory and 
    updates each JSON file by adding a new key-value pair ('mynewkey': 'mynewvalue') if the key 
    doesn't already exist. The function modifies the JSON files in place.

    Parameters:
    directory (str): The directory containing the JSON files.

    Returns:
    int: The number of JSON files updated.

    Requirements:
    - json
    - os
    - glob

    Example:
    >>> task_func('./json_files') # Random test case with no JSON files
    0
    """

instruct prompt

Add a new key-value pair to all JSON files in a specific directory and save the updated JSON files. Specifically, the function searches for all JSON files within the provided directory and updates each JSON file by adding a new key-value pair ('mynewkey': 'mynewvalue') if the key doesn't already exist. The function modifies the JSON files in place.
The function should output with:
    int: The number of JSON files updated.
You should write self-contained code starting with:

Code

import json
import os
import glob
# Constants
KEY = 'mynewkey'
VALUE = 'mynewvalue'
def task_func(directory):

code prompt

Code

import json
import os
import glob
# Constants
KEY = 'mynewkey'
VALUE = 'mynewvalue'
def task_func(directory):

entry point

task_func

libs

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