benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf dee8bd89-cbc0-55a4-8a7a-b7746dfe4c11

Problem

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

complete prompt

import os
import shutil


def task_func(path, delimiter="/"):
    """
    Splits a given file path by a specific delimiter and computes disk usage for each directory component.

    Parameters:
    - path (str): The file path to split.
    - delimiter (str, optional): The delimiter to use for splitting the path. Default is '/'.

    Returns:
    list: A list of tuples where each tuple contains a path component and its disk usage as a dictionary.
          The disk usage dictionary contains keys 'total', 'used', and 'free'.

    Raises:
    - ValueError: If the 'path' is empty, not a string, or contain invalid components.
    - FileNotFoundError: If the 'path' does not exist in the filesystem.

    Requirements:
    - os
    - shutil

    Examples:
    >>> task_func('Docs/src', '/')
    [('Docs', {'total': 100, 'used': 50, 'free': 50}), ('src', {'total': 200, 'used': 100, 'free': 100})]

    >>> task_func('a/b', '/')
    [('a', {'total': 300, 'used': 150, 'free': 150}), ('b', {'total': 400, 'used': 200, 'free': 200})]
    """

instruct prompt

Splits a given file path by a specific delimiter and computes disk usage for each directory component. >>> task_func('a/b', '/') [('a', {'total': 300, 'used': 150, 'free': 150}), ('b', {'total': 400, 'used': 200, 'free': 200})]
The function should raise the exception for: ValueError: If the 'path' is empty, not a string, or contain invalid components. FileNotFoundError: If the 'path' does not exist in the filesystem.
The function should output with:
    list: A list of tuples where each tuple contains a path component and its disk usage as a dictionary.
    The disk usage dictionary contains keys 'total', 'used', and 'free'.
You should write self-contained code starting with:

Code

import os
import shutil
def task_func(path, delimiter="/"):

code prompt

Code

import os
import shutil
def task_func(path, delimiter="/"):

entry point

task_func

libs

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