benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 87d17635-8040-506c-8291-e5af2e84e481

Problem

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

complete prompt

import collections
import random
import string

def task_func(length=100):
    """
    Generate a random string of the specified length composed of uppercase and lowercase letters, 
    and then count the occurrence of each character in this string.

    Parameters:
    length (int, optional): The number of characters in the generated string. Default is 100.

    Returns:
    dict: A dictionary where each key is a character from the generated string and the value 
            is the count of how many times that character appears in the string.

    Requirements:
    - collections
    - random
    - string

    Raises:
    ValueError if the length is a negative number

    Example:
    >>> import random
    >>> random.seed(42)  # Ensures reproducibility for demonstration
    >>> task_func(10)
    {'h': 1, 'B': 2, 'O': 1, 'L': 1, 'm': 1, 'j': 1, 'u': 1, 'E': 1, 'V': 1}
    """

instruct prompt

Generate a random string of the specified length composed of uppercase and lowercase letters, and then count the occurrence of each character in this string.
The function should raise the exception for: ValueError if the length is a negative number
The function should output with:
    dict: A dictionary where each key is a character from the generated string and the value
    is the count of how many times that character appears in the string.
You should write self-contained code starting with:

Code

import collections
import random
import string
def task_func(length=100):

code prompt

Code

import collections
import random
import string
def task_func(length=100):

entry point

task_func

libs

  • collections
  • 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