benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf d0e0fbb5-cffa-5b93-88b8-b1339d26d8a6

Problem

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

complete prompt

import json
import os

def task_func(filename, data):
    """
    Write a dictionary to a file as a JSON object and return the written content for verification.
    
    This function performs a write operation to store the dictionary data in JSON format
    and then reads it back to verify the content. Additionally, checks if the file exists using the os library.

    Parameters:
    - filename (str): The name of the file to be written to.
    - data (dict): The dictionary containing data to be written as JSON to the file.

    Returns:
    - tuple: A tuple containing a boolean indicating the success of the operation and the content that was written.
        - bool: indicating the success of the operation.
        - written_data (json): the content that was written.
    
    Requirements:
    - json
    - os

    Example:
    >>> result, written_data = task_func('data.json', {'key': 'value'})
    >>> print(result)  # This should print: True
    True
    >>> print(written_data)  # This should print: {'key': 'value'}
    {'key': 'value'}
    """

instruct prompt

Write a dictionary to a file as a JSON object and return the written content for verification. This function performs a write operation to store the dictionary data in JSON format and then reads it back to verify the content. Additionally, checks if the file exists using the os library.
The function should output with:
    tuple: A tuple containing a boolean indicating the success of the operation and the content that was written.
    bool: indicating the success of the operation.
    written_data (json): the content that was written.
You should write self-contained code starting with:

Code

import json
import os
def task_func(filename, data):

code prompt

Code

import json
import os
def task_func(filename, data):

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