benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 45f3e7cd-497e-5601-b1a8-348bf4b03c41

Problem

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

complete prompt

import random
import string
import pandas as pd


def task_func(data_list, seed=0):
    """
    Replace a random substring (a sequence of characters between two commas or at the beginning/end of the string)
    in a list of strings with a random string (comprising ascii lowercase characters) with the same length as
    the substituted characters.

    Parameters:
    data_list (list): Input list of strings.
                      Within each string, each substring's leading and trailing whitespaces are removed.
                      If empty, it will return a DataFrame with the Original String and Modified String
                      columns that is otherwise empty.
    seed (int, optional): The seed for random operations to ensure reproducibility. Defaults to 0.

    Returns:
    DataFrame: A pandas DataFrame with two columns - 'Original String' and 'Modified String'.
               'Original String' contains the original strings from the input list, and 'Modified String'
               contains the modified strings where a random substring has been replaced.

    Requirements:
    - pandas
    - random
    - string

    Example:
    >>> task_func(['lamp, bag, mirror', 'table, chair, bag, lamp'])
               Original String          Modified String
    0        lamp, bag, mirror        lamp, tkg, mirror
    1  table, chair, bag, lamp  table, chair, bag, kuhm
    """

instruct prompt

Replace a random substring (a sequence of characters between two commas or at the beginning/end of the string) in a list of strings with a random string (comprising ascii lowercase characters) with the same length as the substituted characters.
The function should output with:
    DataFrame: A pandas DataFrame with two columns - 'Original String' and 'Modified String'.
    'Original String' contains the original strings from the input list, and 'Modified String'
    contains the modified strings where a random substring has been replaced.
You should write self-contained code starting with:

Code

import random
import string
import pandas as pd
def task_func(data_list, seed=0):

code prompt

Code

import random
import string
import pandas as pd
def task_func(data_list, seed=0):

entry point

task_func

libs

  • pandas
  • random
  • string

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