benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf b7e5dd78-f0f1-5406-865d-73116f1af403

Problem

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

complete prompt

import csv
from collections import Counter
import operator

def task_func(csv_file, csv_delimiter):
    """
    Reads a CSV file and counts the most common words in the file.

    This function opens the specified CSV file using the provided delimiter, reads its contents,
    and counts the frequency of each word. It returns a list of tuples, each containing a word 
    and its frequency, sorted by frequency in descending order.

    Note: The function assumes that each cell in the CSV contains a single word.

    Parameters:
        csv_file (str): The path to the CSV file to be read.
        csv_delimiter (str): The delimiter used in the CSV file.

    Requirements:
    - csv
    - collections.Counter
    - operator

    Returns:
        list of tuple: A list of tuples where each tuple contains a word and its count,
                       sorted by count in descending order.

    Examples:
    >>> with open(temp_data.csv, "w") as f:
    >>>     f.write("word1,word2,word3")
    >>> type(task_func('temp_data.csv', ',')) == list
    True
    >>> all(isinstance(pair, tuple) and len(pair) == 2 for pair in task_func('temp_data.csv', ','))
    True
    """

instruct prompt

Reads a CSV file and counts the most common words in the file. This function opens the specified CSV file using the provided delimiter, reads its contents, and counts the frequency of each word. It returns a list of tuples, each containing a word and its frequency, sorted by frequency in descending order.
Note that: The function assumes that each cell in the CSV contains a single word.
The function should output with:
    list of tuple: A list of tuples where each tuple contains a word and its count,
    sorted by count in descending order.
You should write self-contained code starting with:

Code

import csv
from collections import Counter
import operator
def task_func(csv_file, csv_delimiter):

code prompt

Code

import csv
from collections import Counter
import operator
def task_func(csv_file, csv_delimiter):

entry point

task_func

libs

  • operator
  • csv
  • collections

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