benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 02c2687b-6f42-50e0-9221-e117038c8862
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
from collections import Counter
import logging
def task_func(letter_list, element, log_path):
"""
Count the frequency of a particular letter in a given list of letters with logging.
Logs are written to a file named 'task_func.log' with encoding 'utf-8' and logging level DEBUG.
The log file is created by the function or overwritten if already exists.
For each function call the following is logged with the respective logging level:
- info: f"Function called with list: {letter_list} and element: {element}"
- error: if the element is not in the letter list
- info: f"Frequency of '{element}' is {element_frequency}"
After the last info has been logged, the logging is shutdown, such that all
files are released.
Parameters:
letter_list (list of str): The list of letters.
element (str): The specific letter for which the frequency needs to be counted.
log_path (str): the path to the folder in which to save the log file
Returns:
int: The frequency of the letter.
Raises:
ValueError: If element is not in letter_list.
Requirements:
- collections
- logging
Example:
>>> task_func(['a', 'b', 'a', 'c', 'a'], 'a', log_path='./')
3
>>> with open('task_func.log') as log:
... print(log.read())
INFO:Function called with list: ['a', 'b', 'a', 'c', 'a'] and element: a
INFO:Frequency of 'a' is 3
<BLANKLINE>
>>> task_func(['x', 'y', 'z'], 'y', log_path='./')
1
>>> with open('task_func.log') as log:
... print(log.read())
INFO:Function called with list: ['x', 'y', 'z'] and element: y
INFO:Frequency of 'y' is 1
<BLANKLINE>
>>> try:
... task_func(['x', 'y', 'z'], 'a', log_path='./')
... except:
... with open('task_func.log') as log:
... print(log.read())
INFO:Function called with list: ['x', 'y', 'z'] and element: a
ERROR:The element is not in the letter list.
<BLANKLINE>
"""
instruct prompt
Count the frequency of a particular letter in a given list of letters with logging. Logs are written to a file named 'task_func.log' with encoding 'utf-8' and logging level DEBUG. The log file is created by the function or overwritten if already exists. For each function call the following is logged with the respective logging level: - info: f"Function called with list: {letter_list} and element: {element}" - error: if the element is not in the letter list - info: f"Frequency of '{element}' is {element_frequency}" After the last info has been logged, the logging is shutdown, such that all files are released. >>> task_func(['x', 'y', 'z'], 'y', log_path='./') 1 >>> with open('task_func.log') as log: ... print(log.read()) INFO:Function called with list: ['x', 'y', 'z'] and element: y INFO:Frequency of 'y' is 1 <BLANKLINE> >>> try: ... task_func(['x', 'y', 'z'], 'a', log_path='./') ... except: ... with open('task_func.log') as log: ... print(log.read()) INFO:Function called with list: ['x', 'y', 'z'] and element: a ERROR:The element is not in the letter list. <BLANKLINE>
The function should raise the exception for: ValueError: If element is not in letter_list.
The function should output with:
int: The frequency of the letter.
You should write self-contained code starting with:
Code
from collections import Counter
import logging
def task_func(letter_list, element, log_path):
code prompt
Code
from collections import Counter
import logging
def task_func(letter_list, element, log_path):
entry point
task_func
libs
- collections
- logging
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
initial import