benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 949e1fe8-382a-5b73-a3de-c40f4f675af1

Problem

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

complete prompt

import random
import re


def task_func(target_words, n_sentences, vocabulary):
    """
    Generate sentences with spaces in certain target words replaced by underscores.

    Parameters:
    - target_words (list of str): List of words/phrases where spaces should be replaced with underscores.
    - n_sentences (int):          Number of sentences to generate. Must not be negative.
    - vocabulary (list of str):   List of words to use for generating sentences. Must not be empty.

    Returns:
    - list of str: A list of generated sentences in all lowercase, with specified words/phrases underscored.

    Raises:
    - ValueError: If n_sentences is negative or if the vocabulary is empty.

    Requirements:
    - random
    - re

    Notes:
    - Each sentence is generated by randomly sampling 10 words with replacement from a vocabulary,
      then concatenating with a single whitespace. Then, if any words from the target_words list
      appear in these sentences, spaces within those words are replaced with underscores; here the
      modification is insensitive to the case of the letters.
    - The function returns the processed sentences as a list of all lowercase strings.

    Examples:
    >>> random.seed(42)
    >>> task_func(['apple banana'], 1, ['apple', 'banana', 'cherry'])
    ['banana apple apple apple cherry cherry cherry apple_banana apple']
    >>> task_func(['Alice Charlie', 'ALICE BOB', 'aLiCe dAn'], 1, ['alice', 'bob', 'charlie', 'dan'])
    ['alice_charlie alice alice_charlie charlie alice_charlie dan alice']
    """

instruct prompt

Generate sentences with spaces in certain target words replaced by underscores.
Note that: Notes: Each sentence is generated by randomly sampling 10 words with replacement from a vocabulary, then concatenating with a single whitespace. Then, if any words from the target_words list appear in these sentences, spaces within those words are replaced with underscores; here the modification is insensitive to the case of the letters. The function returns the processed sentences as a list of all lowercase strings.
The function should raise the exception for: ValueError: If n_sentences is negative or if the vocabulary is empty.
The function should output with:
    list of str: A list of generated sentences in all lowercase, with specified words/phrases underscored.
You should write self-contained code starting with:

Code

import random
import re
def task_func(target_words, n_sentences, vocabulary):

code prompt

Code

import random
import re
def task_func(target_words, n_sentences, vocabulary):

entry point

task_func

libs

  • random
  • re

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