benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 57c37be6-7565-5cae-8062-8b14ed4e8950
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import pandas as pd
import random
import re
def task_func(data_list, seed=None):
"""
Apply a random operation (remove, replace, shuffle, or randomize) to substrings in a list of strings.
This function processes a list of comma-separated strings by applying one of four random operations to
their substrings: remove, replace, shuffle, or randomize. Here, a substring refers to the individual
items in the string that are separated by commas, sensitive to leading/trailing whitespace, i.e.
'apple' != 'apple ', and sensitive to case, i.e. 'APPLE' != 'aPPLE'.
The choice of operation and the substrings it affects are determined randomly. The operations are:
- Remove: Randomly selects and removes a substring.
If a string contains only one substring, no 'remove' operation is applied.
- Replace: Randomly selects a substring and replaces it with 'random_string'.
- Shuffle: Randomly shuffles the order of the substrings.
- Randomize: Assigns a new, random order to the substrings.
Finally, the function returns a DataFrame with column 'Original String' containing the input strings
and the 'Modified String' column containing the strings after applying the random operation.
Parameters:
- data_list (list): The list of strings. If empty, function will return a DataFrame with the expected
columns that is otherwise empty.
- seed (int, optional): A seed for the random operations to ensure reproducibility. Default is None.
Returns:
df (pd.DataFrame): DataFrame containing original and modified strings.
Requirements:
- pandas
- random
- re
Example:
>>> task_func(['lamp, bag, mirror', 'table, chair, bag, lamp'], seed=0)
Original String Modified String
0 lamp, bag, mirror bag, lamp, mirror
1 table, chair, bag, lamp lamp, chair, bag, table
"""
instruct prompt
Apply a random operation (remove, replace, shuffle, or randomize) to substrings in a list of strings. This function processes a list of comma-separated strings by applying one of four random operations to their substrings: remove, replace, shuffle, or randomize. Here, a substring refers to the individual items in the string that are separated by commas, sensitive to leading/trailing whitespace, i.e. 'apple' != 'apple ', and sensitive to case, i.e. 'APPLE' != 'aPPLE'. The choice of operation and the substrings it affects are determined randomly. The operations are: - Remove: Randomly selects and removes a substring. If a string contains only one substring, no 'remove' operation is applied. - Replace: Randomly selects a substring and replaces it with 'random_string'. - Shuffle: Randomly shuffles the order of the substrings. - Randomize: Assigns a new, random order to the substrings. Finally, the function returns a DataFrame with column 'Original String' containing the input strings and the 'Modified String' column containing the strings after applying the random operation.
The function should output with:
df (pd.DataFrame): DataFrame containing original and modified strings.
You should write self-contained code starting with:
Code
import pandas as pd
import random
import re
def task_func(data_list, seed=None):
code prompt
Code
import pandas as pd
import random
import re
def task_func(data_list, seed=None):
entry point
task_func
libs
- pandas
- random
- re
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
initial import