benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 7619d52c-1ef3-5b6b-8660-e15043770195

Problem

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

complete prompt

import re
import collections


def task_func(string, patterns=['nnn', 'aaa', 'sss', 'ddd', 'fff']):
    """
    Counts the occurrence of specific patterns in a string.
    
    Parameters:
    string (str): The input string.
    patterns (list[str], optional): List of patterns to search for. Defaults to ['nnn', 'aaa', 'sss', 'ddd', 'fff'].
    
    Returns:
    dict: A dictionary with patterns as keys and their counts as values.

    Raises:
    - TypeError: If string is not a str.
    - TypeError: If patterns is not a list of str.
    
    Requirements:
    - re
    - collections
    
    Example:
    >>> task_func("nnnaaaasssdddeeefffggg")
    {'nnn': 1, 'aaa': 1, 'sss': 1, 'ddd': 1, 'fff': 1}
    >>> task_func('asdfasdfasdfasdaaaaf', patterns=['a', 'asdf'])
    {'a': 8, 'asdf': 3}
    >>> task_func('123kajhdlkfah12345k,jk123', patterns=['123', '1234'])
    {'123': 3, '1234': 1}
    """

instruct prompt

Counts the occurrence of specific patterns in a string.
The function should raise the exception for: TypeError: If string is not a str. TypeError: If patterns is not a list of str.
The function should output with:
    dict: A dictionary with patterns as keys and their counts as values.
You should write self-contained code starting with:

Code

import re
import collections
def task_func(string, patterns=['nnn', 'aaa', 'sss', 'ddd', 'fff']):

code prompt

Code

import re
import collections
def task_func(string, patterns=['nnn', 'aaa', 'sss', 'ddd', 'fff']):

entry point

task_func

libs

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