benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a53c5cf9-7891-5bf4-8ddd-2e051d2da12c

Problem

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

complete prompt

import nltk
import re
from collections import Counter


# Constants
STOPWORDS = nltk.corpus.stopwords.words('english')

def task_func(text):
    """
    Calculate the frequency of continuous words in a text string. The function splits the text into words, 
    converts them to lowercase, removes punctuation marks and common stopwords (provided as a constant), 
    and then calculates the frequency of each word.

    Parameters:
    text (str): The input text string.

    Returns:
    dict: A dictionary with words as keys and their frequencies as values.

    Requirements:
    - nltk for stopwords (ensure the stopwords dataset is downloaded using nltk.download('stopwords'))
    - re for regular expressions
    - collections.Counter for counting occurrences

    Example:
    >>> task_func('This is a sample text. This text is for testing.')
    {'sample': 1, 'text': 2, 'testing': 1}
    """

instruct prompt

Calculate the frequency of continuous words in a text string. The function splits the text into words, converts them to lowercase, removes punctuation marks and common stopwords (provided as a constant), and then calculates the frequency of each word.
The function should output with:
    dict: A dictionary with words as keys and their frequencies as values.
You should write self-contained code starting with:

Code

import nltk
import re
from collections import Counter
# Constants
STOPWORDS = nltk.corpus.stopwords.words('english')
def task_func(text):

code prompt

Code

import nltk
import re
from collections import Counter
# Constants
STOPWORDS = nltk.corpus.stopwords.words('english')
def task_func(text):

entry point

task_func

libs

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