benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a1024c35-8b5d-55bf-b275-34457a699e88

Problem

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

complete prompt

import re
import os
from pathlib import Path
import glob


def task_func(directory_path: str, regex_pattern: str = r'\\(.+?\\)|\\w') -> dict:
    """
    Extracts matches from all text files in a specified directory based on a regular expression pattern. 
    It captures whatever is between parentheses as a single match, and any character outside the parentheses 
    as individual matches in the string.

    Parameters:
    - directory_path (str): The path to the directory containing the text files.
    - regex_pattern (str): The regular expression pattern to use for matching. Defaults to REGEX_PATTERN.

    Returns:
    - dict: A dictionary where keys are file names (without path) and values are lists of matches extracted from the files.

    Requirements:
    - Utilizes libraries: re, os, pathlib.Path, and glob.glob

    Example:
    >>> matches = task_func('/path/to/directory') # Test with fictional directory path
    >>> print(matches)
    {}
    """

instruct prompt

Extracts matches from all text files in a specified directory based on a regular expression pattern. It captures whatever is between parentheses as a single match, and any character outside the parentheses as individual matches in the string.
The function should output with:
    dict: A dictionary where keys are file names (without path) and values are lists of matches extracted from the files.
You should write self-contained code starting with:

Code

import re
import os
from pathlib import Path
import glob
def task_func(directory_path: str, regex_pattern: str = r'\\(.+?\\)|\\w') -> dict:

code prompt

Code

import re
import os
from pathlib import Path
import glob
def task_func(directory_path: str, regex_pattern: str = r'\\(.+?\\)|\\w') -> dict:

entry point

task_func

libs

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