benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 82f60e00-289a-5ff9-8db7-2fc23f884ebb

Problem

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

complete prompt

import numpy as np
from difflib import SequenceMatcher
import matplotlib.pyplot as plt

def task_func(s_list, plot_path=None):
    """
    Analyze and plot the average similarity scores of strings in a list.

    This function calculates the average similarity score of each string compared to all other strings in the list using the SequenceMatcher ratio. If a plot path is provided, it saves the plot of these scores; otherwise, it just returns the scores.

    Parameters:
    s_list (list of str): List of strings to analyze.
    plot_path (str, optional): Path to save the plot. If None, plot is not saved.

    Returns:
    list: List of average similarity scores for each string in `s_list`.

    Raises:
    ValueError: If `s_list` is not a list of strings.
    Return numpy.nan if the list contains a single element

    Requirements:
    - numpy
    - difflib
    - matplotlib.pyplot as plt

    Example:
    >>> s_list = ['apple', 'apples', 'ape', 'app', 'april']
    >>> avg_scores = task_func(s_list, 'similarity_plot.png')
    >>> expect = [0.7522727272727273, 0.6969696969696969, 0.6458333333333333, 0.6458333333333333, 0.5363636363636364]
    >>> np.all(np.isclose(avg_scores, expect, atol=1e-4))
    True
    >>> os.remove('similarity_plot.png')
    """

instruct prompt

Analyze and plot the average similarity scores of strings in a list. This function calculates the average similarity score of each string compared to all other strings in the list using the SequenceMatcher ratio. If a plot path is provided, it saves the plot of these scores; otherwise, it just returns the scores.
The function should raise the exception for: ValueError: If `s_list` is not a list of strings. Return numpy.nan if the list contains a single element
The function should output with:
    list: List of average similarity scores for each string in `s_list`.
You should write self-contained code starting with:

Code

import numpy as np
from difflib import SequenceMatcher
import matplotlib.pyplot as plt
def task_func(s_list, plot_path=None):

code prompt

Code

import numpy as np
from difflib import SequenceMatcher
import matplotlib.pyplot as plt
def task_func(s_list, plot_path=None):

entry point

task_func

libs

  • difflib
  • numpy
  • matplotlib

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