benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 5472083d-40e2-5518-9e97-b77092ef45a4

Problem

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

complete prompt

import re
from collections import Counter

def task_func(sentence):
    """
    Count the occurrence of each word in a sentence and return the result as a dictionary.
    This function uses a regular expression to find words and a Counter to count their occurrences.

    Parameters:
    sentence (str): The sentence to count the words in.

    Returns:
    dict: A dictionary where the keys are the words and the values are their counts.

    Requirements:
    - re
    - collections.Counter
    
    Example:
    >>> task_func("apple banana apple orange orange orange")
    {'apple': 2, 'banana': 1, 'orange': 3}
    """

instruct prompt

Count the occurrence of each word in a sentence and return the result as a dictionary. This function uses a regular expression to find words and a Counter to count their occurrences.
The function should output with:
    dict: A dictionary where the keys are the words and the values are their counts.
You should write self-contained code starting with:

Code

import re
from collections import Counter
def task_func(sentence):

code prompt

Code

import re
from collections import Counter
def task_func(sentence):

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