benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 7a0932d8-3f4c-522b-ad75-da8645365161

Problem

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

complete prompt

import pathlib
import os


def task_func(path: str, delimiter: str = os.path.sep) -> list:
    """
    Validates that a given file path does not contain invalid characters for file paths
    then splits it into path components using a specified delimiter.

    Parameters:
    - path (str):      The file path to split. If empty, the function returns an empty list.
    - delimiter (str): The delimiter to use for splitting the path.
                       Defaults to the system's path separator (os.path.sep).

    Returns:
    - list: A list of the path components if the path is valid;
            otherwise, an empty list if the path contains invalid characters.

    Raises:
    - ValueError: If the path contains invalid characters.

    Requirements:
    - pathlib
    - os

    Notes:
    - Backslashes ('\\') are internally converted to forward slashes ('/') before processing.
    - This function treats '<', '>', ':', '"', '|', '?', '*' as invalid characters in paths.

    Examples:
    >>> task_func('Docs/src/Scripts/temp', '/')
    ['Docs', 'src', 'Scripts', 'temp']
    >>> task_func(r'Docs\\src\\Scripts\\temp', '\\\\')
    ['Docs', 'src', 'Scripts', 'temp']
    """

instruct prompt

Validates that a given file path does not contain invalid characters for file paths then splits it into path components using a specified delimiter.
Note that: Notes: Backslashes ('\\') are internally converted to forward slashes ('/') before processing. This function treats '<', '>', ':', '"', '|', '?', '*' as invalid characters in paths.
The function should raise the exception for: ValueError: If the path contains invalid characters.
The function should output with:
    list: A list of the path components if the path is valid;
    otherwise, an empty list if the path contains invalid characters.
You should write self-contained code starting with:

Code

import pathlib
import os
def task_func(path: str, delimiter: str = os.path.sep) -> list:

code prompt

Code

import pathlib
import os
def task_func(path: str, delimiter: str = os.path.sep) -> list:

entry point

task_func

libs

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