benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 8f2a80a4-9ed5-547a-b391-89a6f0108fa0

Problem

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

complete prompt

import pickle
import os
import random
import string

def task_func(strings, filename=None):
    
    """
    Save the list of random strings "Strings" in a pickle file and then read it back for validation.
    If a filename is not provided, a unique filename is generated.

    Parameters:
    - strings (list): The list of random strings to be saved.
    - filename (str, optional): The filename for saving the pickle file. Defaults to a unique generated name.

    Returns:
    - loaded_strings (list): The loaded list of strings from the pickle file.

    Requirements:
    - pickle
    - os
    - random
    - string

    Example:
    >>> strings = [''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) for _ in range(10)]
    >>> loaded_strings = task_func(strings)
    >>> assert strings == loaded_strings
    """

instruct prompt

Save the list of random strings "Strings" in a pickle file and then read it back for validation. If a filename is not provided, a unique filename is generated.
The function should output with:
    loaded_strings (list): The loaded list of strings from the pickle file.
You should write self-contained code starting with:

Code

import pickle
import os
import random
import string
def task_func(strings, filename=None):

code prompt

Code

import pickle
import os
import random
import string
def task_func(strings, filename=None):

entry point

task_func

libs

  • pickle
  • string
  • random
  • 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