benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 1219053f-8186-5006-b155-8370adda8873

Problem

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

complete prompt

import ast
import os
import glob

# Constants
DIRECTORY = 'data'

def task_func(directory):
    """
    Convert all Unicode string representations of dictionaries in all text files 
    in the specified directory to Python dictionaries.

    Parameters:
    directory (str): The path to the directory containing the text files.

    Returns:
    list: A list of dictionaries extracted from the text files.

    Requirements:
    - ast
    - os
    - glob

    Example:
    >>> task_func("sample_directory/")
    [{'key1': 'value1'}, {'key2': 'value2'}]

    Note:
    Ensure that the text files in the directory contain valid Unicode string representations of dictionaries.

    Raises:
    - The function would raise a ValueError if there are text file(s) that have invalid dictionary representation
    """

instruct prompt

Convert all Unicode string representations of dictionaries in all text files in the specified directory to Python dictionaries.
Note that: Ensure that the text files in the directory contain valid Unicode string representations of dictionaries.
The function should raise the exception for: The function would raise a ValueError if there are text file(s) that have invalid dictionary representation
The function should output with:
    list: A list of dictionaries extracted from the text files.
You should write self-contained code starting with:

Code

import ast
import os
import glob
# Constants
DIRECTORY = 'data'
def task_func(directory):

code prompt

Code

import ast
import os
import glob
# Constants
DIRECTORY = 'data'
def task_func(directory):

entry point

task_func

libs

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