benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 82f37747-f404-53c6-9a19-c1904bd9109b
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import collections
import operator
import os
import shutil
def task_func(data_dict, source_directory, backup_directory):
"""
Modifies a dictionary, sorts it by the frequency of its values, and backs up files from a source directory.
This function performs three main tasks:
1. Updates the input dictionary by adding a key 'a' with the value 1.
2. Sorts the dictionary by the frequency of its values in descending order.
3. Backs up all files from the specified source directory to a backup directory.
Parameters:
data_dict (dict): The dictionary to be modified and sorted.
source_directory (str): The path to the source directory containing files to be backed up.
backup_directory (str): The path to the backup directory where files will be copied.
Returns:
tuple:
- dict: The modified dictionary with the added key and value.
- list: A list of tuples representing the sorted items of the dictionary by their frequency.
- bool: A boolean indicating whether the backup was successful (True) or not (False).
Requirements:
- collections
- operator
- os
- shutil
Examples:
>>> data_dict = {'b': 'val1', 'c': 'val2'}
>>> updated_dict, value_frequencies, backup_status = task_func(data_dict, 'folder1', 'backup_folder')
>>> print(updated_dict)
{'a': 1, 'key1': 'value1', 'key2': 'value2'}
>>> print(value_frequencies)
[('val1', 1), ('val2', 1), (1, 1)]
>>> print(backup_status)
True
>>> data_dict = {'avc': '1', 'hello': 'world', 'test': 'world', 'cat': 'meow'}
>>> updated_dict, value_frequencies, backup_status = task_func(data_dict, 'to_backup', 'backup')
>>> print(updated_dict)
{'a': 1, 'avc': '1', 'hello': 'world', 'test': 'world', 'cat': 'meow'}
>>> print(value_frequencies)
[('avc', 1), ('world', 2), ('meow', 1), (1, 2)]
>>> print(backup_status)
True
"""
instruct prompt
Modifies a dictionary, sorts it by the frequency of its values, and backs up files from a source directory. This function performs three main tasks: 1. Updates the input dictionary by adding a key 'a' with the value 1. 2. Sorts the dictionary by the frequency of its values in descending order. 3. Backs up all files from the specified source directory to a backup directory. >>> data_dict = {'avc': '1', 'hello': 'world', 'test': 'world', 'cat': 'meow'} >>> updated_dict, value_frequencies, backup_status = task_func(data_dict, 'to_backup', 'backup') >>> print(updated_dict) {'a': 1, 'avc': '1', 'hello': 'world', 'test': 'world', 'cat': 'meow'} >>> print(value_frequencies) [('avc', 1), ('world', 2), ('meow', 1), (1, 2)] >>> print(backup_status) True
The function should output with:
tuple:
dict: The modified dictionary with the added key and value.
list: A list of tuples representing the sorted items of the dictionary by their frequency.
bool: A boolean indicating whether the backup was successful (True) or not (False).
You should write self-contained code starting with:
Code
import collections
import operator
import os
import shutil
def task_func(data_dict, source_directory, backup_directory):
code prompt
Code
import collections
import operator
import os
import shutil
def task_func(data_dict, source_directory, backup_directory):
entry point
task_func
libs
- operator
- shutil
- collections
- os
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