benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf f5335ba7-8b09-56c0-89b7-30f7043aab4f

Problem

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

complete prompt

import os
import glob
import hashlib

def task_func(source_dir, target_dir, prefix='#Hash: '):
    """
    Computes the MD5 hash of each file's content in the specified `source_dir`, prepends the hash along with a prefix 
    to the original content, and writes the modified content to new files in the `target_dir`. 
    Existing files with the same name in `target_dir` are overwritten.

    Parameters:
    - source_dir (str): The directory containing the files to be processed. Must exist.
    - target_dir (str): The directory where the processed files will be written. Created if it does not exist.
    - prefix (str): The prefix to prepend before the hash in each new file. Default is '#Hash: '.

    Returns:
    - list: A list of paths to the newly created files in the `target_dir`, each with the hash prepended.

    Requirements:
    - os
    - glob
    - hashlib

    Raises:
    FileNotFoundError if the source directory does not exist.

    Example:
    >>> task_func(source_dir='samples', target_dir='hashed_samples', prefix='#MD5: ')
    ['hashed_samples/file1.txt', 'hashed_samples/file2.txt']
    """

instruct prompt

Computes the MD5 hash of each file's content in the specified `source_dir`, prepends the hash along with a prefix to the original content, and writes the modified content to new files in the `target_dir`. Existing files with the same name in `target_dir` are overwritten.
The function should raise the exception for: FileNotFoundError if the source directory does not exist.
The function should output with:
    list: A list of paths to the newly created files in the `target_dir`, each with the hash prepended.
You should write self-contained code starting with:

Code

import os
import glob
import hashlib
def task_func(source_dir, target_dir, prefix='#Hash: '):

code prompt

Code

import os
import glob
import hashlib
def task_func(source_dir, target_dir, prefix='#Hash: '):

entry point

task_func

libs

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