benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 38030736-f57c-512d-a4a7-5418f13a12b2

Problem

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

complete prompt

import json
from collections import Counter
import random

def task_func(my_dict, keys):
    """
    Updates a given dictionary by adding 10 random elements based on the 'keys' parameter,
    with values as random integers from 1 to 100. It saves the JSON representation of the
    updated dictionary to a file and the counts of each key to a separate text file.

    Parameters:
        my_dict (dict): The dictionary to be updated.
        keys (list of str): A list of keys to be added to the dictionary.

    Returns:
        tuple: The dictionary, path to the JSON file, and path to the text file.

    Raises:
        ValueError: If 'keys' does not contain exactly 10 unique elements.

    Note:
        This function modifies the input dictionary in place.
        The filename of the json is 'updated_dictionary.json'
        The filename of the txt file is 'key_frequencies.txt'

    Requirements:
    - json
    - collections.Counter
    - random

    Examples:
    >>> result, json_path, txt_path = task_func({'first_key': 1, 'second_key': 2}, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])
    >>> isinstance(result, dict)
    True
    >>> len(result) > 2  # Checking if more keys have been added
    True
    """

instruct prompt

Updates a given dictionary by adding 10 random elements based on the 'keys' parameter, with values as random integers from 1 to 100. It saves the JSON representation of the updated dictionary to a file and the counts of each key to a separate text file.
Note that: This function modifies the input dictionary in place. The filename of the json is 'updated_dictionary.json' The filename of the txt file is 'key_frequencies.txt'
The function should raise the exception for: ValueError: If 'keys' does not contain exactly 10 unique elements.
The function should output with:
    tuple: The dictionary, path to the JSON file, and path to the text file.
You should write self-contained code starting with:

Code

import json
from collections import Counter
import random
def task_func(my_dict, keys):

code prompt

Code

import json
from collections import Counter
import random
def task_func(my_dict, keys):

entry point

task_func

libs

  • collections
  • random
  • json

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